Browse Source

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

* Set up localization for static portfolio analysis rules: Economic Market Cluster Risks

* Update changelog
pull/5182/head
Tobias Kugel 5 days ago
committed by GitHub
parent
commit
44ea3cba8d
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 5
      CHANGELOG.md
  2. 8
      apps/api/src/app/portfolio/portfolio.service.ts
  3. 4
      apps/api/src/app/user/user.service.ts
  4. 58
      apps/api/src/models/rules/economic-market-cluster-risk/developed-markets.ts
  5. 58
      apps/api/src/models/rules/economic-market-cluster-risk/emerging-markets.ts
  6. 36
      apps/client/src/app/pages/i18n/i18n-page.html

5
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

8
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

4
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

58
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 {

58
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 {

36
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">

Loading…
Cancel
Save