Browse Source
Feature/support localization in date fns (#1195)
* Add locale to date-fns (formatDistanceToNow)
* Update changelog
pull/1193/head^2
Thomas Kaul
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
19 additions and
1 deletions
-
CHANGELOG.md
-
apps/client/src/app/components/home-summary/home-summary.html
-
apps/client/src/app/components/portfolio-summary/portfolio-summary.component.ts
-
libs/common/src/lib/helper.ts
|
|
@ -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`) |
|
|
|
|
|
@ -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)" |
|
|
|
|
|
@ -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 = '-'; |
|
|
|
} |
|
|
|
|
|
@ -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() |
|
|
|