From fa1e711a25cdc6acbfdd0de4bd1d903fa2e5b5f3 Mon Sep 17 00:00:00 2001 From: Florian Dupret <34862846+sephrat@users.noreply.github.com> Date: Tue, 19 Oct 2021 11:14:38 +0200 Subject: [PATCH] Localize dates --- src/Ombi/ClientApp/src/app/app.module.ts | 33 +++++++++++++++++++ .../details-group.component.html | 2 +- .../movie-information-panel.component.html | 6 ++-- .../tv-information-panel.component.html | 2 +- .../ClientApp/src/app/pipes/LocalizedDate.ts | 16 +++++++++ .../ClientApp/src/app/pipes/pipe.module.ts | 5 +-- .../about/update-dialog.component.html | 2 +- 7 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 src/Ombi/ClientApp/src/app/pipes/LocalizedDate.ts diff --git a/src/Ombi/ClientApp/src/app/app.module.ts b/src/Ombi/ClientApp/src/app/app.module.ts index b4e78087c..d22edbfbc 100644 --- a/src/Ombi/ClientApp/src/app/app.module.ts +++ b/src/Ombi/ClientApp/src/app/app.module.ts @@ -66,6 +66,39 @@ import { TranslateHttpLoader } from "@ngx-translate/http-loader"; import { UnauthorizedInterceptor } from "./auth/unauthorized.interceptor"; import { environment } from "../environments/environment"; +import { registerLocaleData } from '@angular/common'; +// TODO: lazy load locales, probably somewhere in app.component +import localeDa from '@angular/common/locales/da'; +import localeDe from '@angular/common/locales/de'; +import localeEs from '@angular/common/locales/es'; +import localeFr from '@angular/common/locales/fr'; +import localeIt from '@angular/common/locales/it'; +import localeHu from '@angular/common/locales/hu'; +import localeNl from '@angular/common/locales/nl'; +// import localeNo from '@angular/common/locales/no'; +import localePl from '@angular/common/locales/pl'; +import localePt from '@angular/common/locales/pt'; +import localeSk from '@angular/common/locales/sk'; +import localeSv from '@angular/common/locales/sv'; +import localeBg from '@angular/common/locales/bg'; +import localeRu from '@angular/common/locales/ru'; + + +registerLocaleData(localeDa); +registerLocaleData(localeDe); +registerLocaleData(localeEs); +registerLocaleData(localeFr); +registerLocaleData(localeIt); +registerLocaleData(localeHu); +registerLocaleData(localeNl); +// registerLocaleData(localeNo); +registerLocaleData(localePl); +registerLocaleData(localePt); +registerLocaleData(localeSk); +registerLocaleData(localeSv); +registerLocaleData(localeBg); +registerLocaleData(localeRu); + const routes: Routes = [ { path: "*", component: PageNotFoundComponent }, { path: "", redirectTo: "/discover", pathMatch: "full" }, diff --git a/src/Ombi/ClientApp/src/app/issues/components/details-group/details-group.component.html b/src/Ombi/ClientApp/src/app/issues/components/details-group/details-group.component.html index c4906baac..46a77d575 100644 --- a/src/Ombi/ClientApp/src/app/issues/components/details-group/details-group.component.html +++ b/src/Ombi/ClientApp/src/app/issues/components/details-group/details-group.component.html @@ -1,7 +1,7 @@ {{issue.subject}} - {{issue.userReported?.userName}} on {{issue.createdDate | date:short}} + {{issue.userReported?.userName}} on {{issue.createdDate | localizedDate:short}}

diff --git a/src/Ombi/ClientApp/src/app/media-details/components/movie/panels/movie-information-panel.component.html b/src/Ombi/ClientApp/src/app/media-details/components/movie/panels/movie-information-panel.component.html index 2e88e6edc..480e19ddd 100644 --- a/src/Ombi/ClientApp/src/app/media-details/components/movie/panels/movie-information-panel.component.html +++ b/src/Ombi/ClientApp/src/app/media-details/components/movie/panels/movie-information-panel.component.html @@ -50,7 +50,7 @@

{{'MediaDetails.RequestDate' | translate }} - {{request.requestedDate | date}} + {{request.requestedDate | localizedDate}}
@@ -78,11 +78,11 @@
{{'MediaDetails.TheatricalRelease' | translate }} - {{movie.releaseDate | date: 'mediumDate'}} + {{movie.releaseDate | localizedDate: 'mediumDate'}}
{{'MediaDetails.DigitalRelease' | translate }} - {{movie.digitalReleaseDate | date: 'mediumDate'}} + {{movie.digitalReleaseDate | localizedDate: 'mediumDate'}}
diff --git a/src/Ombi/ClientApp/src/app/media-details/components/tv/panels/tv-information-panel/tv-information-panel.component.html b/src/Ombi/ClientApp/src/app/media-details/components/tv/panels/tv-information-panel/tv-information-panel.component.html index 6f7278c6b..ddf6fd44c 100644 --- a/src/Ombi/ClientApp/src/app/media-details/components/tv/panels/tv-information-panel/tv-information-panel.component.html +++ b/src/Ombi/ClientApp/src/app/media-details/components/tv/panels/tv-information-panel/tv-information-panel.component.html @@ -25,7 +25,7 @@ {{ getTVStatusLabel()}}
{{'MediaDetails.FirstAired' | translate }} - {{tv.firstAired | date: 'mediumDate'}} + {{tv.firstAired | localizedDate: 'mediumDate'}}
diff --git a/src/Ombi/ClientApp/src/app/pipes/LocalizedDate.ts b/src/Ombi/ClientApp/src/app/pipes/LocalizedDate.ts new file mode 100644 index 000000000..ab71fa36d --- /dev/null +++ b/src/Ombi/ClientApp/src/app/pipes/LocalizedDate.ts @@ -0,0 +1,16 @@ +import { DatePipe } from '@angular/common'; +import { Pipe, PipeTransform } from '@angular/core'; +import { TranslateService } from '@ngx-translate/core'; + +@Pipe({ + name: 'localizedDate', + pure: false + }) +export class LocalizedDatePipe implements PipeTransform { + constructor(private translateService: TranslateService) {} + + transform(value: any, pattern: string = 'mediumDate'): any { + const datePipe: DatePipe = new DatePipe(this.translateService.currentLang); + return datePipe.transform(value, pattern); + } +} \ No newline at end of file diff --git a/src/Ombi/ClientApp/src/app/pipes/pipe.module.ts b/src/Ombi/ClientApp/src/app/pipes/pipe.module.ts index 8e084ec3d..f41924060 100644 --- a/src/Ombi/ClientApp/src/app/pipes/pipe.module.ts +++ b/src/Ombi/ClientApp/src/app/pipes/pipe.module.ts @@ -1,5 +1,6 @@ import { ModuleWithProviders, NgModule } from "@angular/core"; import { HumanizePipe } from "./HumanizePipe"; +import { LocalizedDatePipe } from "./LocalizedDate"; import { ThousandShortPipe } from "./ThousandShortPipe"; import { SafePipe } from "./SafePipe"; import { QualityPipe } from "./QualityPipe"; @@ -7,8 +8,8 @@ import { UserLocalePipe } from "./UserLocalePipe"; @NgModule({ imports: [], - declarations: [HumanizePipe, ThousandShortPipe, SafePipe, QualityPipe, UserLocalePipe], - exports: [HumanizePipe, ThousandShortPipe, SafePipe, QualityPipe, UserLocalePipe], + declarations: [HumanizePipe, ThousandShortPipe, SafePipe, QualityPipe, UserLocalePipe, LocalizedDatePipe ], + exports: [HumanizePipe, ThousandShortPipe, SafePipe, QualityPipe, UserLocalePipe, LocalizedDatePipe ], }) export class PipeModule { diff --git a/src/Ombi/ClientApp/src/app/settings/about/update-dialog.component.html b/src/Ombi/ClientApp/src/app/settings/about/update-dialog.component.html index 77b053e0a..2327f2834 100644 --- a/src/Ombi/ClientApp/src/app/settings/about/update-dialog.component.html +++ b/src/Ombi/ClientApp/src/app/settings/about/update-dialog.component.html @@ -18,7 +18,7 @@
-Updated at {{data.updateDate | date}} +Updated at {{data.updateDate | localizedDate}}