From b40ad4362db25312098341dfdb8645fee7b19f9c Mon Sep 17 00:00:00 2001 From: tobikugel Date: Sun, 1 Jun 2025 18:15:42 -0300 Subject: [PATCH] implements interpolation in i18n service --- .../fees/fee-ratio-initial-investment.ts | 30 ++++++++++--------- apps/api/src/services/i18n/i18n.service.ts | 12 ++++++-- apps/client/src/locales/messages.de.xlf | 16 ++++++++++ apps/client/src/locales/messages.fr.xlf | 16 ++++++++++ apps/client/src/locales/messages.it.xlf | 16 ++++++++++ apps/client/src/locales/messages.nl.xlf | 16 ++++++++++ apps/client/src/locales/messages.pl.xlf | 16 ++++++++++ apps/client/src/locales/messages.pt.xlf | 16 ++++++++++ apps/client/src/locales/messages.tr.xlf | 16 ++++++++++ apps/client/src/locales/messages.uk.xlf | 16 ++++++++++ apps/client/src/locales/messages.xlf | 14 +++++++++ apps/client/src/locales/messages.zh.xlf | 16 ++++++++++ 12 files changed, 184 insertions(+), 16 deletions(-) diff --git a/apps/api/src/models/rules/fees/fee-ratio-initial-investment.ts b/apps/api/src/models/rules/fees/fee-ratio-initial-investment.ts index d19d57b9f..8c546133e 100644 --- a/apps/api/src/models/rules/fees/fee-ratio-initial-investment.ts +++ b/apps/api/src/models/rules/fees/fee-ratio-initial-investment.ts @@ -30,13 +30,14 @@ export class FeeRatioInitialInvestment extends Rule { : 0; if (feeRatio > ruleSettings.thresholdMax) { - const evaluation = this.i18nService - .getTranslation({ - id: 'rule.fee-ratio-initial-investment.exceed', - languageCode: DEFAULT_LANGUAGE_CODE - }) - .replace('{thresholdMax}', (ruleSettings.thresholdMax * 100).toFixed(2)) - .replace('{feeRatio}', (feeRatio * 100).toPrecision(3)); + const evaluation = this.i18nService.getTranslation({ + id: 'rule.fee-ratio-initial-investment.exceed', + languageCode: DEFAULT_LANGUAGE_CODE, + placeholders: { + feeRatio: (ruleSettings.thresholdMax * 100).toFixed(2), + thresholdMax: (feeRatio * 100).toPrecision(3) + } + }); return { evaluation, @@ -44,13 +45,14 @@ export class FeeRatioInitialInvestment extends Rule { }; } - const evaluation = this.i18nService - .getTranslation({ - id: 'rule.fee-ratio-initial-investment.not-exceed', - languageCode: DEFAULT_LANGUAGE_CODE - }) - .replace('{thresholdMax}', (ruleSettings.thresholdMax * 100).toFixed(2)) - .replace('{feeRatio}', (feeRatio * 100).toPrecision(3)); + const evaluation = this.i18nService.getTranslation({ + id: 'rule.fee-ratio-initial-investment.not-exceed', + languageCode: DEFAULT_LANGUAGE_CODE, + placeholders: { + feeRatio: (feeRatio * 100).toPrecision(3), + thresholdMax: (ruleSettings.thresholdMax * 100).toFixed(2) + } + }); return { evaluation, diff --git a/apps/api/src/services/i18n/i18n.service.ts b/apps/api/src/services/i18n/i18n.service.ts index 13193fc6a..e928775d1 100644 --- a/apps/api/src/services/i18n/i18n.service.ts +++ b/apps/api/src/services/i18n/i18n.service.ts @@ -15,10 +15,12 @@ export class I18nService { public getTranslation({ id, - languageCode + languageCode, + placeholders }: { id: string; languageCode: string; + placeholders?: Record; }): string { const $ = this.translations[languageCode]; @@ -26,7 +28,7 @@ export class I18nService { Logger.warn(`Translation not found for locale '${languageCode}'`); } - const translatedText = $( + let translatedText = $( `trans-unit[id="${id}"] > ${ languageCode === DEFAULT_LANGUAGE_CODE ? 'source' : 'target' }` @@ -38,6 +40,12 @@ export class I18nService { ); } + if (placeholders) { + for (const [key, value] of Object.entries(placeholders)) { + translatedText = translatedText.replace(`{${key}}`, String(value)); + } + } + return translatedText.trim(); } diff --git a/apps/client/src/locales/messages.de.xlf b/apps/client/src/locales/messages.de.xlf index a791049a3..3cd354e84 100644 --- a/apps/client/src/locales/messages.de.xlf +++ b/apps/client/src/locales/messages.de.xlf @@ -7620,6 +7620,22 @@ 181 + + Demo user account has been synced. + Demo user account has been synced. + + apps/client/src/app/components/admin-overview/admin-overview.component.ts + 223 + + + + Sync Demo User Account + Sync Demo User Account + + apps/client/src/app/components/admin-overview/admin-overview.html + 181 + + diff --git a/apps/client/src/locales/messages.fr.xlf b/apps/client/src/locales/messages.fr.xlf index 3481054a8..68230c7fa 100644 --- a/apps/client/src/locales/messages.fr.xlf +++ b/apps/client/src/locales/messages.fr.xlf @@ -7620,6 +7620,22 @@ 181 + + The fees do exceed {thresholdMax}% of your initial investment ({feeRatio}%) + The fees do exceed {thresholdMax}% of your initial investment ({feeRatio}%) + + apps/client/src/app/pages/i18n/i18n-page.html + 14 + + + + The fees do not exceed {thresholdMax}% of your initial investment ({feeRatio}%) + The fees do not exceed {thresholdMax}% of your initial investment ({feeRatio}%) + + apps/client/src/app/pages/i18n/i18n-page.html + 18 + + diff --git a/apps/client/src/locales/messages.it.xlf b/apps/client/src/locales/messages.it.xlf index 5659235c3..b0898653e 100644 --- a/apps/client/src/locales/messages.it.xlf +++ b/apps/client/src/locales/messages.it.xlf @@ -7621,6 +7621,22 @@ 181 + + The fees do exceed {thresholdMax}% of your initial investment ({feeRatio}%) + The fees do exceed {thresholdMax}% of your initial investment ({feeRatio}%) + + apps/client/src/app/pages/i18n/i18n-page.html + 14 + + + + The fees do not exceed {thresholdMax}% of your initial investment ({feeRatio}%) + The fees do not exceed {thresholdMax}% of your initial investment ({feeRatio}%) + + apps/client/src/app/pages/i18n/i18n-page.html + 18 + + diff --git a/apps/client/src/locales/messages.nl.xlf b/apps/client/src/locales/messages.nl.xlf index b13de3379..44250ab06 100644 --- a/apps/client/src/locales/messages.nl.xlf +++ b/apps/client/src/locales/messages.nl.xlf @@ -7620,6 +7620,22 @@ 181 + + The fees do exceed {thresholdMax}% of your initial investment ({feeRatio}%) + The fees do exceed {thresholdMax}% of your initial investment ({feeRatio}%) + + apps/client/src/app/pages/i18n/i18n-page.html + 14 + + + + The fees do not exceed {thresholdMax}% of your initial investment ({feeRatio}%) + The fees do not exceed {thresholdMax}% of your initial investment ({feeRatio}%) + + apps/client/src/app/pages/i18n/i18n-page.html + 18 + + diff --git a/apps/client/src/locales/messages.pl.xlf b/apps/client/src/locales/messages.pl.xlf index 94d9a4a17..b7b92376c 100644 --- a/apps/client/src/locales/messages.pl.xlf +++ b/apps/client/src/locales/messages.pl.xlf @@ -7620,6 +7620,22 @@ 181 + + The fees do exceed {thresholdMax}% of your initial investment ({feeRatio}%) + The fees do exceed {thresholdMax}% of your initial investment ({feeRatio}%) + + apps/client/src/app/pages/i18n/i18n-page.html + 14 + + + + The fees do not exceed {thresholdMax}% of your initial investment ({feeRatio}%) + The fees do not exceed {thresholdMax}% of your initial investment ({feeRatio}%) + + apps/client/src/app/pages/i18n/i18n-page.html + 18 + + diff --git a/apps/client/src/locales/messages.pt.xlf b/apps/client/src/locales/messages.pt.xlf index 500078150..ca6c5c84b 100644 --- a/apps/client/src/locales/messages.pt.xlf +++ b/apps/client/src/locales/messages.pt.xlf @@ -7620,6 +7620,22 @@ 181 + + The fees do exceed {thresholdMax}% of your initial investment ({feeRatio}%) + The fees do exceed {thresholdMax}% of your initial investment ({feeRatio}%) + + apps/client/src/app/pages/i18n/i18n-page.html + 14 + + + + The fees do not exceed {thresholdMax}% of your initial investment ({feeRatio}%) + The fees do not exceed {thresholdMax}% of your initial investment ({feeRatio}%) + + apps/client/src/app/pages/i18n/i18n-page.html + 18 + + diff --git a/apps/client/src/locales/messages.tr.xlf b/apps/client/src/locales/messages.tr.xlf index e073d30ac..6187bf0f5 100644 --- a/apps/client/src/locales/messages.tr.xlf +++ b/apps/client/src/locales/messages.tr.xlf @@ -7620,6 +7620,22 @@ 181 + + Demo user account has been synced. + Demo user account has been synced. + + apps/client/src/app/components/admin-overview/admin-overview.component.ts + 223 + + + + Sync Demo User Account + Sync Demo User Account + + apps/client/src/app/components/admin-overview/admin-overview.html + 181 + + diff --git a/apps/client/src/locales/messages.uk.xlf b/apps/client/src/locales/messages.uk.xlf index 1977eff9b..53c1a4442 100644 --- a/apps/client/src/locales/messages.uk.xlf +++ b/apps/client/src/locales/messages.uk.xlf @@ -7620,6 +7620,22 @@ 181 + + The fees do exceed {thresholdMax}% of your initial investment ({feeRatio}%) + The fees do exceed {thresholdMax}% of your initial investment ({feeRatio}%) + + apps/client/src/app/pages/i18n/i18n-page.html + 14 + + + + The fees do not exceed {thresholdMax}% of your initial investment ({feeRatio}%) + The fees do not exceed {thresholdMax}% of your initial investment ({feeRatio}%) + + apps/client/src/app/pages/i18n/i18n-page.html + 18 + + diff --git a/apps/client/src/locales/messages.xlf b/apps/client/src/locales/messages.xlf index a7da886fe..1f984b8a5 100644 --- a/apps/client/src/locales/messages.xlf +++ b/apps/client/src/locales/messages.xlf @@ -6852,6 +6852,20 @@ 223 + + The fees do exceed {thresholdMax}% of your initial investment ({feeRatio}%) + + apps/client/src/app/pages/i18n/i18n-page.html + 14 + + + + The fees do not exceed {thresholdMax}% of your initial investment ({feeRatio}%) + + apps/client/src/app/pages/i18n/i18n-page.html + 18 + + diff --git a/apps/client/src/locales/messages.zh.xlf b/apps/client/src/locales/messages.zh.xlf index fea34c62d..a4a7de741 100644 --- a/apps/client/src/locales/messages.zh.xlf +++ b/apps/client/src/locales/messages.zh.xlf @@ -7621,6 +7621,22 @@ 181 + + The fees do exceed {thresholdMax}% of your initial investment ({feeRatio}%) + The fees do exceed {thresholdMax}% of your initial investment ({feeRatio}%) + + apps/client/src/app/pages/i18n/i18n-page.html + 14 + + + + The fees do not exceed {thresholdMax}% of your initial investment ({feeRatio}%) + The fees do not exceed {thresholdMax}% of your initial investment ({feeRatio}%) + + apps/client/src/app/pages/i18n/i18n-page.html + 18 + +