Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Feature/set up localization for static portfolio analysis rules: Economic Market Cluster Risks (#5169)

Tobias Kugel44ea3cba8d24
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5efe62150d..61c69f5353 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
+### Added
+
+- Set up the language localization for the static portfolio analysis rule: _Economic Market Cluster Risks_ (Developed Markets)
+- Set up the language localization for the static portfolio analysis rule: _Economic Market Cluster Risks_ (Emerging Markets)
+
### Changed
- Improved the platform icon in the create or update platform dialog of the admin control
diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts
index a343015c5b..4d09edf8bb 100644
--- a/apps/api/src/app/portfolio/portfolio.service.ts
+++ b/apps/api/src/app/portfolio/portfolio.service.ts
@@ -1223,13 +1223,17 @@ export class PortfolioService {
[
new EconomicMarketClusterRiskDevelopedMarkets(
this.exchangeRateDataService,
+ this.i18nService,
marketsTotalInBaseCurrency,
- markets.developedMarkets.valueInBaseCurrency
+ markets.developedMarkets.valueInBaseCurrency,
+ userSettings.language
),
new EconomicMarketClusterRiskEmergingMarkets(
this.exchangeRateDataService,
+ this.i18nService,
marketsTotalInBaseCurrency,
- markets.emergingMarkets.valueInBaseCurrency
+ markets.emergingMarkets.valueInBaseCurrency,
+ userSettings.language
)
],
userSettings
diff --git a/apps/api/src/app/user/user.service.ts b/apps/api/src/app/user/user.service.ts
index 14da872081..a69167b3b1 100644
--- a/apps/api/src/app/user/user.service.ts
+++ b/apps/api/src/app/user/user.service.ts
@@ -300,12 +300,16 @@ export class UserService {
).getSettings(user.settings.settings),
EconomicMarketClusterRiskDevelopedMarkets:
new EconomicMarketClusterRiskDevelopedMarkets(
+ undefined,
+ undefined,
undefined,
undefined,
undefined
).getSettings(user.settings.settings),
EconomicMarketClusterRiskEmergingMarkets:
new EconomicMarketClusterRiskEmergingMarkets(
+ undefined,
+ undefined,
undefined,
undefined,
undefined
diff --git a/apps/api/src/models/rules/economic-market-cluster-risk/developed-markets.ts b/apps/api/src/models/rules/economic-market-cluster-risk/developed-markets.ts
index d2c8fdae92..7ca7a2d769 100644
--- a/apps/api/src/models/rules/economic-market-cluster-risk/developed-markets.ts
+++ b/apps/api/src/models/rules/economic-market-cluster-risk/developed-markets.ts
@@ -1,6 +1,7 @@
import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface';
import { Rule } from '@ghostfolio/api/models/rule';
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service';
+import { I18nService } from '@ghostfolio/api/services/i18n/i18n.service';
import { UserSettings } from '@ghostfolio/common/interfaces';
export class EconomicMarketClusterRiskDevelopedMarkets extends Rule<Settings> {
@@ -9,10 +10,13 @@ export class EconomicMarketClusterRiskDevelopedMarkets extends Rule<Settings> {
public constructor(
protected exchangeRateDataService: ExchangeRateDataService,
+ private i18nService: I18nService,
currentValueInBaseCurrency: number,
- developedMarketsValueInBaseCurrency: number
+ developedMarketsValueInBaseCurrency: number,
+ languageCode: string
) {
super(exchangeRateDataService, {
+ languageCode,
key: EconomicMarketClusterRiskDevelopedMarkets.name
});
@@ -29,32 +33,55 @@ export class EconomicMarketClusterRiskDevelopedMarkets extends Rule<Settings> {
if (developedMarketsValueRatio > ruleSettings.thresholdMax) {
return {
- evaluation: `The developed markets contribution of your current investment (${(developedMarketsValueRatio * 100).toPrecision(3)}%) exceeds ${(
- ruleSettings.thresholdMax * 100
- ).toPrecision(3)}%`,
+ evaluation: this.i18nService.getTranslation({
+ id: 'rule.economicMarketClusterRiskDevelopedMarkets.false.max',
+ languageCode: this.getLanguageCode(),
+ placeholders: {
+ developedMarketsValueRatio: (
+ developedMarketsValueRatio * 100
+ ).toPrecision(3),
+ thresholdMax: (ruleSettings.thresholdMax * 100).toPrecision(3)
+ }
+ }),
value: false
};
} else if (developedMarketsValueRatio < ruleSettings.thresholdMin) {
return {
- evaluation: `The developed markets contribution of your current investment (${(developedMarketsValueRatio * 100).toPrecision(3)}%) is below ${(
- ruleSettings.thresholdMin * 100
- ).toPrecision(3)}%`,
+ evaluation: this.i18nService.getTranslation({
+ id: 'rule.economicMarketClusterRiskDevelopedMarkets.false.min',
+ languageCode: this.getLanguageCode(),
+ placeholders: {
+ developedMarketsValueRatio: (
+ developedMarketsValueRatio * 100
+ ).toPrecision(3),
+ thresholdMin: (ruleSettings.thresholdMin * 100).toPrecision(3)
+ }
+ }),
value: false
};
}
return {
- evaluation: `The developed markets contribution of your current investment (${(developedMarketsValueRatio * 100).toPrecision(3)}%) is within the range of ${(
- ruleSettings.thresholdMin * 100
- ).toPrecision(
- 3
- )}% and ${(ruleSettings.thresholdMax * 100).toPrecision(3)}%`,
+ evaluation: this.i18nService.getTranslation({
+ id: 'rule.economicMarketClusterRiskDevelopedMarkets.true',
+ languageCode: this.getLanguageCode(),
+ placeholders: {
+ developedMarketsValueRatio: (
+ developedMarketsValueRatio * 100
+ ).toPrecision(3),
+ thresholdMin: (ruleSettings.thresholdMin * 100).toPrecision(3),
+ thresholdMax: (ruleSettings.thresholdMax * 100).toPrecision(3)
+ }
+ }),
value: true
};
}
public getCategoryName() {
- return 'Economic Market Cluster Risk'; // TODO: Replace hardcoded text with i18n translation
+ return this.i18nService.getTranslation({
+ id: 'rule.economicMarketClusterRisk.category',
+ languageCode: this.getLanguageCode()
+ });
}
public getConfiguration() {
@@ -71,7 +98,10 @@ export class EconomicMarketClusterRiskDevelopedMarkets extends Rule<Settings> {
}
public getName() {
- return 'Developed Markets';
+ return this.i18nService.getTranslation({
+ id: 'rule.economicMarketClusterRiskDevelopedMarkets',
+ languageCode: this.getLanguageCode()
+ });
}
public getSettings({ baseCurrency, xRayRules }: UserSettings): Settings {
diff --git a/apps/api/src/models/rules/economic-market-cluster-risk/emerging-markets.ts b/apps/api/src/models/rules/economic-market-cluster-risk/emerging-markets.ts
index fd3c0ab67c..cbf9f98b7c 100644
--- a/apps/api/src/models/rules/economic-market-cluster-risk/emerging-markets.ts
+++ b/apps/api/src/models/rules/economic-market-cluster-risk/emerging-markets.ts
@@ -1,6 +1,7 @@
import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface';
import { Rule } from '@ghostfolio/api/models/rule';
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service';
+import { I18nService } from '@ghostfolio/api/services/i18n/i18n.service';
import { UserSettings } from '@ghostfolio/common/interfaces';
export class EconomicMarketClusterRiskEmergingMarkets extends Rule<Settings> {
@@ -9,10 +10,13 @@ export class EconomicMarketClusterRiskEmergingMarkets extends Rule<Settings> {
public constructor(
protected exchangeRateDataService: ExchangeRateDataService,
+ private i18nService: I18nService,
currentValueInBaseCurrency: number,
- emergingMarketsValueInBaseCurrency: number
+ emergingMarketsValueInBaseCurrency: number,
+ languageCode: string
) {
super(exchangeRateDataService, {
+ languageCode,
key: EconomicMarketClusterRiskEmergingMarkets.name
});
@@ -29,32 +33,55 @@ export class EconomicMarketClusterRiskEmergingMarkets extends Rule<Settings> {
if (emergingMarketsValueRatio > ruleSettings.thresholdMax) {
return {
- evaluation: `The emerging markets contribution of your current investment (${(emergingMarketsValueRatio * 100).toPrecision(3)}%) exceeds ${(
- ruleSettings.thresholdMax * 100
- ).toPrecision(3)}%`,
+ evaluation: this.i18nService.getTranslation({
+ id: 'rule.economicMarketClusterRiskEmergingMarkets.false.max',
+ languageCode: this.getLanguageCode(),
+ placeholders: {
+ emergingMarketsValueRatio: (
+ emergingMarketsValueRatio * 100
+ ).toPrecision(3),
+ thresholdMax: (ruleSettings.thresholdMax * 100).toPrecision(3)
+ }
+ }),
value: false
};
} else if (emergingMarketsValueRatio < ruleSettings.thresholdMin) {
return {
- evaluation: `The emerging markets contribution of your current investment (${(emergingMarketsValueRatio * 100).toPrecision(3)}%) is below ${(
- ruleSettings.thresholdMin * 100
- ).toPrecision(3)}%`,
+ evaluation: this.i18nService.getTranslation({
+ id: 'rule.economicMarketClusterRiskEmergingMarkets.false.min',
+ languageCode: this.getLanguageCode(),
+ placeholders: {
+ emergingMarketsValueRatio: (
+ emergingMarketsValueRatio * 100
+ ).toPrecision(3),
+ thresholdMin: (ruleSettings.thresholdMin * 100).toPrecision(3)
+ }
+ }),
value: false
};
}
return {
- evaluation: `The emerging markets contribution of your current investment (${(emergingMarketsValueRatio * 100).toPrecision(3)}%) is within the range of ${(
- ruleSettings.thresholdMin * 100
- ).toPrecision(
- 3
- )}% and ${(ruleSettings.thresholdMax * 100).toPrecision(3)}%`,
+ evaluation: this.i18nService.getTranslation({
+ id: 'rule.economicMarketClusterRiskEmergingMarkets.true',
+ languageCode: this.getLanguageCode(),
+ placeholders: {
+ emergingMarketsValueRatio: (
+ emergingMarketsValueRatio * 100
+ ).toPrecision(3),
+ thresholdMin: (ruleSettings.thresholdMin * 100).toPrecision(3),
+ thresholdMax: (ruleSettings.thresholdMax * 100).toPrecision(3)
+ }
+ }),
value: true
};
}
public getCategoryName() {
- return 'Economic Market Cluster Risk'; // TODO: Replace hardcoded text with i18n translation
+ return this.i18nService.getTranslation({
+ id: 'rule.economicMarketClusterRisk.category',
+ languageCode: this.getLanguageCode()
+ });
}
public getConfiguration() {
@@ -71,7 +98,10 @@ export class EconomicMarketClusterRiskEmergingMarkets extends Rule<Settings> {
}
public getName() {
- return 'Emerging Markets';
+ return this.i18nService.getTranslation({
+ id: 'rule.economicMarketClusterRiskEmergingMarkets',
+ languageCode: this.getLanguageCode()
+ });
}
public getSettings({ baseCurrency, xRayRules }: UserSettings): Settings {
diff --git a/apps/client/src/app/pages/i18n/i18n-page.html b/apps/client/src/app/pages/i18n/i18n-page.html
index 9f130f295e..bb5a00cc0d 100644
--- a/apps/client/src/app/pages/i18n/i18n-page.html
+++ b/apps/client/src/app/pages/i18n/i18n-page.html
@@ -86,6 +86,42 @@
<li i18n="@@rule.economicMarketClusterRisk.category">
Economic Market Cluster Risks
</li>
+ <li i18n="@@rule.economicMarketClusterRiskDevelopedMarkets">
+ Developed Markets
+ </li>
+ <li i18n="@@rule.economicMarketClusterRiskDevelopedMarkets.false.max">
+ The developed markets contribution of your current investment
+ ($&#123;developedMarketsValueRatio&#125;%) exceeds
+ $&#123;thresholdMax&#125;%
+ </li>
+ <li i18n="@@rule.economicMarketClusterRiskDevelopedMarkets.false.min">
+ The developed markets contribution of your current investment
+ ($&#123;developedMarketsValueRatio&#125;%) is below
+ $&#123;thresholdMin&#125;%
+ </li>
+ <li i18n="@@rule.economicMarketClusterRiskDevelopedMarkets.true">
+ The developed markets contribution of your current investment
+ ($&#123;developedMarketsValueRatio&#125;%) is within the range of
+ $&#123;thresholdMin&#125;% and $&#123;thresholdMax&#125;%
+ </li>
+ <li i18n="@@rule.economicMarketClusterRiskEmergingMarkets">
+ Emerging Markets
+ </li>
+ <li i18n="@@rule.economicMarketClusterRiskEmergingMarkets.false.max">
+ The emerging markets contribution of your current investment
+ ($&#123;emergingMarketsValueRatio&#125;%) exceeds
+ $&#123;thresholdMax&#125;%
+ </li>
+ <li i18n="@@rule.economicMarketClusterRiskEmergingMarkets.false.min">
+ The emerging markets contribution of your current investment
+ ($&#123;emergingMarketsValueRatio&#125;%) is below
+ $&#123;thresholdMin&#125;%
+ </li>
+ <li i18n="@@rule.economicMarketClusterRiskEmergingMarkets.true">
+ The emerging markets contribution of your current investment
+ ($&#123;emergingMarketsValueRatio&#125;%) is within the range of
+ $&#123;thresholdMin&#125;% and $&#123;thresholdMax&#125;%
+ </li>
<li i18n="@@rule.emergencyFund.category">Emergency Fund</li>
<li i18n="@@rule.emergencyFundSetup">Set up</li>
<li i18n="@@rule.emergencyFundSetup.false">