Browse Source

Localize country names

pull/6995/head
Thomas Kaul 3 days ago
parent
commit
5d23c8faad
  1. 6
      apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts
  2. 7
      apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html
  3. 12
      apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts
  4. 7
      apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html
  5. 9
      apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts
  6. 6
      apps/client/src/app/pages/public/public-page.component.ts
  7. 14
      libs/common/src/lib/helper.ts
  8. 29
      libs/ui/src/lib/i18n.ts

6
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
};
}

7
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</gf-value
>
</div>

12
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
};
}

7
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</gf-value
>
</div>

9
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)

6
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]

14
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;

29
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`,

Loading…
Cancel
Save