From 13d56e50ae27235e8390414e1fc8c8404d24ed3b Mon Sep 17 00:00:00 2001 From: CoderNadir Date: Sat, 25 Nov 2023 15:28:36 +0100 Subject: [PATCH] feat: feat/#7175-translate-date translate date when language change --- apps/gauzy/src/app/app.component.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/gauzy/src/app/app.component.ts b/apps/gauzy/src/app/app.component.ts index acbbf118f23..6bd8fcb2339 100644 --- a/apps/gauzy/src/app/app.component.ts +++ b/apps/gauzy/src/app/app.component.ts @@ -6,7 +6,7 @@ import { AfterViewInit, Component, OnInit } from '@angular/core'; import { Router, ActivatedRoute, NavigationEnd } from '@angular/router'; import { SeoService } from './@core/utils/seo.service'; -import { TranslateService } from '@ngx-translate/core'; +import { LangChangeEvent, TranslateService } from '@ngx-translate/core'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { IDateRangePicker, ILanguage, LanguagesEnum } from '@gauzy/contracts'; import { isNotEmpty } from '@gauzy/common-angular'; @@ -26,6 +26,7 @@ import { import { environment } from '../environments/environment'; import { JitsuService } from './@core/services/analytics/jitsu.service'; import { union } from 'underscore'; +import { moment } from './@core/moment-extend'; @UntilDestroy({ checkProperties: true }) @Component({ @@ -59,6 +60,11 @@ export class AppComponent implements OnInit, AfterViewInit { this.jitsuService.trackPageViews(); this.seoService.trackCanonicalChanges(); + // -- Translate date when language change + this.translate.onLangChange.subscribe( + (langChangeEvent: LangChangeEvent) => moment.locale(langChangeEvent.lang) + ) + this.store.systemLanguages$ .pipe(untilDestroyed(this)) .subscribe((languages) => { @@ -66,7 +72,7 @@ export class AppComponent implements OnInit, AfterViewInit { const browserLang = this.translate.getBrowserLang(); //Gets default enum languages, e.g. "en", "bg", "he", "ru" - const defaultLanguages = Object.values(LanguagesEnum); + const defaultLanguages: string[] = Object.values(LanguagesEnum); //Gets system languages let systemLanguages: string[] = _.pluck(languages, 'code');