Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Feature/support localization in date fns (#1195)
Thomas Kaul2db46e5bbfbe
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6bafcdcc8f..74fe7db59f 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.htmlindex 7905130bdb..9401db451c 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.tsindex 7a69f0d586..7b1bce9ac2 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.tsindex f60e039f4a..dfb200346e 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()