Browse Source

Feature/language localization for static portfolio analysis rule: Currency Cluster Risks (#5038)

* Language localization for static portfolio analysis rule: Currency Cluster Risks

* Update changelog
pull/5041/head
csehatt741 4 days ago
committed by GitHub
parent
commit
351fd8a1d4
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      CHANGELOG.md
  2. 8
      apps/api/src/app/portfolio/portfolio.service.ts
  3. 4
      apps/api/src/app/user/user.service.ts
  4. 37
      apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts
  5. 41
      apps/api/src/models/rules/currency-cluster-risk/current-investment.ts
  6. 21
      apps/client/src/app/pages/i18n/i18n-page.html

2
CHANGELOG.md

@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Set up the language localization for the static portfolio analysis rule: _Asset Class Cluster Risks_ (Equity) - Set up the language localization for the static portfolio analysis rule: _Asset Class Cluster Risks_ (Equity)
- Set up the language localization for the static portfolio analysis rule: _Asset Class Cluster Risks_ (Fixed Income) - Set up the language localization for the static portfolio analysis rule: _Asset Class Cluster Risks_ (Fixed Income)
- Set up the language localization for the static portfolio analysis rule: _Currency Cluster Risks_ (Investment)
- Set up the language localization for the static portfolio analysis rule: _Currency Cluster Risks_ (Investment: Base Currency)
### Changed ### Changed

8
apps/api/src/app/portfolio/portfolio.service.ts

@ -1300,11 +1300,15 @@ export class PortfolioService {
[ [
new CurrencyClusterRiskBaseCurrencyCurrentInvestment( new CurrencyClusterRiskBaseCurrencyCurrentInvestment(
this.exchangeRateDataService, this.exchangeRateDataService,
Object.values(holdings) this.i18nService,
Object.values(holdings),
userSettings.language
), ),
new CurrencyClusterRiskCurrentInvestment( new CurrencyClusterRiskCurrentInvestment(
this.exchangeRateDataService, this.exchangeRateDataService,
Object.values(holdings) this.i18nService,
Object.values(holdings),
userSettings.language
) )
], ],
userSettings userSettings

4
apps/api/src/app/user/user.service.ts

@ -285,11 +285,15 @@ export class UserService {
).getSettings(user.Settings.settings), ).getSettings(user.Settings.settings),
CurrencyClusterRiskBaseCurrencyCurrentInvestment: CurrencyClusterRiskBaseCurrencyCurrentInvestment:
new CurrencyClusterRiskBaseCurrencyCurrentInvestment( new CurrencyClusterRiskBaseCurrencyCurrentInvestment(
undefined,
undefined,
undefined, undefined,
undefined undefined
).getSettings(user.Settings.settings), ).getSettings(user.Settings.settings),
CurrencyClusterRiskCurrentInvestment: CurrencyClusterRiskCurrentInvestment:
new CurrencyClusterRiskCurrentInvestment( new CurrencyClusterRiskCurrentInvestment(
undefined,
undefined,
undefined, undefined,
undefined undefined
).getSettings(user.Settings.settings), ).getSettings(user.Settings.settings),

37
apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts

@ -1,6 +1,7 @@
import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface'; import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface';
import { Rule } from '@ghostfolio/api/models/rule'; import { Rule } from '@ghostfolio/api/models/rule';
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service';
import { I18nService } from '@ghostfolio/api/services/i18n/i18n.service';
import { PortfolioPosition, UserSettings } from '@ghostfolio/common/interfaces'; import { PortfolioPosition, UserSettings } from '@ghostfolio/common/interfaces';
export class CurrencyClusterRiskBaseCurrencyCurrentInvestment extends Rule<Settings> { export class CurrencyClusterRiskBaseCurrencyCurrentInvestment extends Rule<Settings> {
@ -8,10 +9,13 @@ export class CurrencyClusterRiskBaseCurrencyCurrentInvestment extends Rule<Setti
public constructor( public constructor(
protected exchangeRateDataService: ExchangeRateDataService, protected exchangeRateDataService: ExchangeRateDataService,
holdings: PortfolioPosition[] private i18nService: I18nService,
holdings: PortfolioPosition[],
languageCode: string
) { ) {
super(exchangeRateDataService, { super(exchangeRateDataService, {
key: CurrencyClusterRiskBaseCurrencyCurrentInvestment.name key: CurrencyClusterRiskBaseCurrencyCurrentInvestment.name,
languageCode
}); });
this.holdings = holdings; this.holdings = holdings;
@ -48,17 +52,29 @@ export class CurrencyClusterRiskBaseCurrencyCurrentInvestment extends Rule<Setti
if (maxItem?.groupKey !== ruleSettings.baseCurrency) { if (maxItem?.groupKey !== ruleSettings.baseCurrency) {
return { return {
evaluation: `The major part of your current investment is not in your base currency (${( evaluation: this.i18nService.getTranslation({
baseCurrencyValueRatio * 100 id: 'rule.currencyClusterRiskBaseCurrencyCurrentInvestment.false',
).toPrecision(3)}% in ${ruleSettings.baseCurrency})`, languageCode: this.getLanguageCode(),
placeholders: {
baseCurrency: ruleSettings.baseCurrency,
baseCurrencyValueRatio: (baseCurrencyValueRatio * 100).toPrecision(
3
)
}
}),
value: false value: false
}; };
} }
return { return {
evaluation: `The major part of your current investment is in your base currency (${( evaluation: this.i18nService.getTranslation({
baseCurrencyValueRatio * 100 id: 'rule.currencyClusterRiskBaseCurrencyCurrentInvestment.true',
).toPrecision(3)}% in ${ruleSettings.baseCurrency})`, languageCode: this.getLanguageCode(),
placeholders: {
baseCurrency: ruleSettings.baseCurrency,
baseCurrencyValueRatio: (baseCurrencyValueRatio * 100).toPrecision(3)
}
}),
value: true value: true
}; };
} }
@ -68,7 +84,10 @@ export class CurrencyClusterRiskBaseCurrencyCurrentInvestment extends Rule<Setti
} }
public getName() { public getName() {
return 'Investment: Base Currency'; return this.i18nService.getTranslation({
id: 'rule.currencyClusterRiskBaseCurrencyCurrentInvestment',
languageCode: this.getLanguageCode()
});
} }
public getSettings({ baseCurrency, xRayRules }: UserSettings): Settings { public getSettings({ baseCurrency, xRayRules }: UserSettings): Settings {

41
apps/api/src/models/rules/currency-cluster-risk/current-investment.ts

@ -1,6 +1,7 @@
import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface'; import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface';
import { Rule } from '@ghostfolio/api/models/rule'; import { Rule } from '@ghostfolio/api/models/rule';
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service';
import { I18nService } from '@ghostfolio/api/services/i18n/i18n.service';
import { PortfolioPosition, UserSettings } from '@ghostfolio/common/interfaces'; import { PortfolioPosition, UserSettings } from '@ghostfolio/common/interfaces';
export class CurrencyClusterRiskCurrentInvestment extends Rule<Settings> { export class CurrencyClusterRiskCurrentInvestment extends Rule<Settings> {
@ -8,10 +9,13 @@ export class CurrencyClusterRiskCurrentInvestment extends Rule<Settings> {
public constructor( public constructor(
protected exchangeRateDataService: ExchangeRateDataService, protected exchangeRateDataService: ExchangeRateDataService,
holdings: PortfolioPosition[] private i18nService: I18nService,
holdings: PortfolioPosition[],
languageCode: string
) { ) {
super(exchangeRateDataService, { super(exchangeRateDataService, {
key: CurrencyClusterRiskCurrentInvestment.name key: CurrencyClusterRiskCurrentInvestment.name,
languageCode
}); });
this.holdings = holdings; this.holdings = holdings;
@ -41,21 +45,29 @@ export class CurrencyClusterRiskCurrentInvestment extends Rule<Settings> {
if (maxValueRatio > ruleSettings.thresholdMax) { if (maxValueRatio > ruleSettings.thresholdMax) {
return { return {
evaluation: `Over ${ evaluation: this.i18nService.getTranslation({
ruleSettings.thresholdMax * 100 id: 'rule.currencyClusterRiskCurrentInvestment.false',
}% of your current investment is in ${maxItem.groupKey} (${( languageCode: this.getLanguageCode(),
maxValueRatio * 100 placeholders: {
).toPrecision(3)}%)`, currency: maxItem.groupKey as string,
maxValueRatio: (maxValueRatio * 100).toPrecision(3),
thresholdMax: ruleSettings.thresholdMax * 100
}
}),
value: false value: false
}; };
} }
return { return {
evaluation: `The major part of your current investment is in ${ evaluation: this.i18nService.getTranslation({
maxItem?.groupKey ?? ruleSettings.baseCurrency id: 'rule.currencyClusterRiskCurrentInvestment.true',
} (${(maxValueRatio * 100).toPrecision(3)}%) and does not exceed ${ languageCode: this.getLanguageCode(),
ruleSettings.thresholdMax * 100 placeholders: {
}%`, currency: maxItem.groupKey as string,
maxValueRatio: (maxValueRatio * 100).toPrecision(3),
thresholdMax: ruleSettings.thresholdMax * 100
}
}),
value: true value: true
}; };
} }
@ -73,7 +85,10 @@ export class CurrencyClusterRiskCurrentInvestment extends Rule<Settings> {
} }
public getName() { public getName() {
return 'Investment'; return this.i18nService.getTranslation({
id: 'rule.currencyClusterRiskCurrentInvestment',
languageCode: this.getLanguageCode()
});
} }
public getSettings({ baseCurrency, xRayRules }: UserSettings): Settings { public getSettings({ baseCurrency, xRayRules }: UserSettings): Settings {

21
apps/client/src/app/pages/i18n/i18n-page.html

@ -57,6 +57,27 @@
($&#123;fixedIncomeValueRatio&#125;%) is within the range of ($&#123;fixedIncomeValueRatio&#125;%) is within the range of
$&#123;thresholdMin&#125;% and $&#123;thresholdMax&#125;% $&#123;thresholdMin&#125;% and $&#123;thresholdMax&#125;%
</li> </li>
<li i18n="@@rule.currencyClusterRiskBaseCurrencyCurrentInvestment">
Investment: Base Currency
</li>
<li i18n="@@rule.currencyClusterRiskBaseCurrencyCurrentInvestment.false">
The major part of your current investment is not in your base currency
($&#123;baseCurrencyValueRatio&#125;% in $&#123;baseCurrency&#125;)
</li>
<li i18n="@@rule.currencyClusterRiskBaseCurrencyCurrentInvestment.true">
The major part of your current investment is in your base currency
($&#123;baseCurrencyValueRatio&#125;% in $&#123;baseCurrency&#125;)
</li>
<li i18n="@@rule.currencyClusterRiskCurrentInvestment">Investment</li>
<li i18n="@@rule.currencyClusterRiskCurrentInvestment.false">
Over $&#123;thresholdMax&#125;% of your current investment is in
$&#123;currency&#125; ($&#123;maxValueRatio&#125;%)
</li>
<li i18n="@@rule.currencyClusterRiskCurrentInvestment.true">
The major part of your current investment is in $&#123;currency&#125;
($&#123;maxValueRatio&#125;%) and does not exceed
$&#123;thresholdMax&#125;%
</li>
<li i18n="@@rule.emergencyFundSetup">Emergency Fund: Set up</li> <li i18n="@@rule.emergencyFundSetup">Emergency Fund: Set up</li>
<li i18n="@@rule.emergencyFundSetup.false"> <li i18n="@@rule.emergencyFundSetup.false">
No emergency fund has been set up No emergency fund has been set up

Loading…
Cancel
Save