diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bafcdcc8..74fe7db59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Added support for translated time distances + ### Changed - Improved the language localization for German (`de`) diff --git a/apps/client/src/app/components/home-summary/home-summary.html b/apps/client/src/app/components/home-summary/home-summary.html index 7905130bd..9401db451 100644 --- a/apps/client/src/app/components/home-summary/home-summary.html +++ b/apps/client/src/app/components/home-summary/home-summary.html @@ -10,6 +10,7 @@ [baseCurrency]="user?.settings?.baseCurrency" [hasPermissionToUpdateUserSettings]="!hasImpersonationId && hasPermissionToUpdateUserSettings" [isLoading]="isLoading" + [language]="user?.settings?.language" [locale]="user?.settings?.locale" [summary]="summary" (emergencyFundChanged)="onChangeEmergencyFund($event)" diff --git a/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.ts b/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.ts index 7a69f0d58..7b1bce9ac 100644 --- a/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.ts +++ b/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.ts @@ -7,6 +7,7 @@ import { OnInit, Output } from '@angular/core'; +import { getDateFnsLocale } from '@ghostfolio/common/helper'; import { PortfolioSummary } from '@ghostfolio/common/interfaces'; import { formatDistanceToNow } from 'date-fns'; @@ -20,6 +21,7 @@ export class PortfolioSummaryComponent implements OnChanges, OnInit { @Input() baseCurrency: string; @Input() hasPermissionToUpdateUserSettings: boolean; @Input() isLoading: boolean; + @Input() language: string; @Input() locale: string; @Input() summary: PortfolioSummary; @@ -34,7 +36,9 @@ export class PortfolioSummaryComponent implements OnChanges, OnInit { public ngOnChanges() { if (this.summary) { if (this.summary.firstOrderDate) { - this.timeInMarket = formatDistanceToNow(this.summary.firstOrderDate); + this.timeInMarket = formatDistanceToNow(this.summary.firstOrderDate, { + locale: getDateFnsLocale(this.language) + }); } else { this.timeInMarket = '-'; } diff --git a/libs/common/src/lib/helper.ts b/libs/common/src/lib/helper.ts index f60e039f4..dfb200346 100644 --- a/libs/common/src/lib/helper.ts +++ b/libs/common/src/lib/helper.ts @@ -1,6 +1,7 @@ import * as currencies from '@dinero.js/currencies'; import { DataSource } from '@prisma/client'; import { getDate, getMonth, getYear, parse, subDays } from 'date-fns'; +import { de } from 'date-fns/locale'; import { ghostfolioScraperApiSymbolPrefix, locale } from './config'; import { Benchmark } from './interfaces'; @@ -56,6 +57,14 @@ export function getCssVariable(aCssVariable: string) { ); } +export function getDateFnsLocale(aLanguageCode: string) { + if (aLanguageCode === 'de') { + return de; + } + + return undefined; +} + export function getDateFormatString(aLocale?: string) { const formatObject = new Intl.DateTimeFormat(aLocale).formatToParts( new Date()