diff --git a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts index 7d25748e0..ce997cf27 100644 --- a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts +++ b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts @@ -8,6 +8,7 @@ import { UpdateAssetProfileDto } from '@ghostfolio/common/dtos'; import { canDeleteAssetProfile, DATE_FORMAT, + getCountryName, getCurrencyFromSymbol, isCurrency } from '@ghostfolio/common/helper'; @@ -224,6 +225,7 @@ export class GfAssetProfileDialogComponent implements OnInit { value: 'max' } ]; + protected readonly getCountryName = getCountryName; protected historicalDataItems: LineChartItem[]; protected isBenchmark = false; protected isDataGatheringEnabled: boolean; @@ -369,9 +371,9 @@ export class GfAssetProfileDialogComponent implements OnInit { this.assetProfile?.countries && this.assetProfile.countries.length > 0 ) { - for (const { code, name, weight } of this.assetProfile.countries) { + for (const { code, weight } of this.assetProfile.countries) { this.countries[code] = { - name: translate(name), + name: getCountryName({ code, locale: this.data.locale }), value: weight }; } diff --git a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html index 75ff7adbb..d9a5354e5 100644 --- a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html +++ b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html @@ -269,7 +269,12 @@ i18n size="medium" [locale]="data.locale" - [value]="translate(assetProfile?.countries[0].name)" + [value]=" + getCountryName({ + code: assetProfile?.countries[0].code, + locale: data.locale + }) + " >Country diff --git a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts index 11de90c18..68bb1215a 100644 --- a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts +++ b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts @@ -6,7 +6,11 @@ import { NUMERICAL_PRECISION_THRESHOLD_6_FIGURES } from '@ghostfolio/common/config'; import { CreateOrderDto } from '@ghostfolio/common/dtos'; -import { DATE_FORMAT, downloadAsFile } from '@ghostfolio/common/helper'; +import { + DATE_FORMAT, + downloadAsFile, + getCountryName +} from '@ghostfolio/common/helper'; import { Activity, DataProviderInfo, @@ -121,6 +125,7 @@ export class GfHoldingDetailDialogComponent implements OnInit { public dividendInBaseCurrencyPrecision = 2; public dividendYieldPercentWithCurrencyEffect: number; public feeInBaseCurrency: number; + public getCountryName = getCountryName; public hasPermissionToCreateOwnTag: boolean; public hasPermissionToReadMarketDataOfOwnAssetProfile: boolean; public historicalDataItems: LineChartItem[]; @@ -434,7 +439,10 @@ export class GfHoldingDetailDialogComponent implements OnInit { if (SymbolProfile?.countries?.length > 0) { for (const country of SymbolProfile.countries) { this.countries[country.code] = { - name: translate(country.name), + name: getCountryName({ + code: country.code, + locale: this.data.locale + }), value: country.weight }; } diff --git a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html index c80e3dbde..609eec3c0 100644 --- a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html +++ b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html @@ -272,7 +272,12 @@ i18n size="medium" [locale]="data.locale" - [value]="translate(SymbolProfile.countries[0].name)" + [value]=" + getCountryName({ + code: SymbolProfile.countries[0].code, + locale: data.locale + }) + " >Country diff --git a/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts b/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts index aff1c205a..d0eb3788b 100644 --- a/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts +++ b/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts @@ -3,7 +3,7 @@ import { AccountDetailDialogParams } from '@ghostfolio/client/components/account import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service'; import { UserService } from '@ghostfolio/client/services/user/user.service'; import { MAX_TOP_HOLDINGS, UNKNOWN_KEY } from '@ghostfolio/common/config'; -import { prettifySymbol } from '@ghostfolio/common/helper'; +import { getCountryName, prettifySymbol } from '@ghostfolio/common/helper'; import { AssetProfileIdentifier, HoldingWithParents, @@ -353,7 +353,7 @@ export class GfAllocationsPageComponent implements OnInit { if (position.assetProfile.countries.length > 0) { for (const country of position.assetProfile.countries) { - const { code, continent, name, weight } = country; + const { code, continent, weight } = country; if (this.continents[continent]?.value) { this.continents[continent].value += @@ -380,7 +380,10 @@ export class GfAllocationsPageComponent implements OnInit { : position.valueInPercentage); } else { this.countries[code] = { - name: translate(name), + name: getCountryName({ + code, + locale: this.user?.settings?.locale + }), value: weight * (isNumber(position.valueInBaseCurrency) diff --git a/apps/client/src/app/pages/public/public-page.component.ts b/apps/client/src/app/pages/public/public-page.component.ts index 91c392cd1..43d961c1d 100644 --- a/apps/client/src/app/pages/public/public-page.component.ts +++ b/apps/client/src/app/pages/public/public-page.component.ts @@ -1,5 +1,5 @@ import { UNKNOWN_KEY } from '@ghostfolio/common/config'; -import { prettifySymbol } from '@ghostfolio/common/helper'; +import { getCountryName, prettifySymbol } from '@ghostfolio/common/helper'; import { InfoItem, PortfolioPosition, @@ -186,7 +186,7 @@ export class GfPublicPageComponent implements OnInit { if (position.assetProfile.countries.length > 0) { for (const country of position.assetProfile.countries) { - const { code, continent, name, weight } = country; + const { code, continent, weight } = country; if (this.continents[continent]?.value) { this.continents[continent].value += @@ -206,7 +206,7 @@ export class GfPublicPageComponent implements OnInit { weight * (position.valueInBaseCurrency ?? 0); } else { this.countries[code] = { - name: translate(name), + name: getCountryName({ code }), value: weight * (this.publicPortfolioDetails.holdings[symbol] diff --git a/libs/common/src/lib/helper.ts b/libs/common/src/lib/helper.ts index 02bd26b90..db320c7cb 100644 --- a/libs/common/src/lib/helper.ts +++ b/libs/common/src/lib/helper.ts @@ -258,6 +258,20 @@ export function getCurrencyFromSymbol(aSymbol = '') { return aSymbol.replace(DEFAULT_CURRENCY, ''); } +export function getCountryName({ + code, + locale = getLocale() +}: { + code: string; + locale?: string; +}) { + try { + return new Intl.DisplayNames([locale], { type: 'region' }).of(code) ?? code; + } catch { + return code; + } +} + export function getDateFnsLocale(aLanguageCode?: string) { if (aLanguageCode === 'ca') { return ca; diff --git a/libs/ui/src/lib/i18n.ts b/libs/ui/src/lib/i18n.ts index f6f1e8ff9..2c037c7d1 100644 --- a/libs/ui/src/lib/i18n.ts +++ b/libs/ui/src/lib/i18n.ts @@ -75,35 +75,6 @@ const locales = { Oceania: $localize`Oceania`, 'South America': $localize`South America`, - // Countries - Armenia: $localize`Armenia`, - Argentina: $localize`Argentina`, - Australia: $localize`Australia`, - Austria: $localize`Austria`, - Belgium: $localize`Belgium`, - 'British Virgin Islands': $localize`British Virgin Islands`, - Bulgaria: $localize`Bulgaria`, - Canada: $localize`Canada`, - 'Czech Republic': $localize`Czech Republic`, - Finland: $localize`Finland`, - France: $localize`France`, - Germany: $localize`Germany`, - India: $localize`India`, - Indonesia: $localize`Indonesia`, - Italy: $localize`Italy`, - Japan: $localize`Japan`, - Netherlands: $localize`Netherlands`, - 'New Zealand': $localize`New Zealand`, - Poland: $localize`Poland`, - Romania: $localize`Romania`, - Singapore: $localize`Singapore`, - 'South Africa': $localize`South Africa`, - Switzerland: $localize`Switzerland`, - Thailand: $localize`Thailand`, - Ukraine: $localize`Ukraine`, - 'United Kingdom': $localize`United Kingdom`, - 'United States': $localize`United States`, - // Fear and Greed Index EXTREME_FEAR: $localize`Extreme Fear`, EXTREME_GREED: $localize`Extreme Greed`,