From bb857d58ccdfbb3f4ba16bb2f4484618d3551848 Mon Sep 17 00:00:00 2001 From: _Bastler <_Bastler@bstly.de> Date: Sun, 20 Mar 2022 13:32:10 +0100 Subject: [PATCH] fix i18n --- src/app/app.module.ts | 4 +--- src/app/services/i18n.service.ts | 31 ++++++++++--------------------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 821e9f7..700e848 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -69,9 +69,7 @@ import { JukeboxComponent } from './pages/jukebox/jukebox.compontent'; export function init_app(i18n: I18nService) { - return () => { - i18n.fetch(); - }; + return () => i18n.fetch() } @Injectable() diff --git a/src/app/services/i18n.service.ts b/src/app/services/i18n.service.ts index 22b5681..4044f87 100644 --- a/src/app/services/i18n.service.ts +++ b/src/app/services/i18n.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { environment } from '../../environments/environment'; import { MatPaginatorIntl } from '@angular/material/paginator'; -import { Subject } from 'rxjs'; +import { Subject, firstValueFrom } from 'rxjs'; @Injectable({ providedIn: 'root', @@ -10,7 +10,7 @@ import { Subject } from 'rxjs'; export class I18nService { locale: string = "de-informal"; - locales: any[] = [ "de-informal" ]; + locales: any = [ "de-informal" ]; i18n: any; constructor(private http: HttpClient) { @@ -30,12 +30,7 @@ export class I18nService { } async fetch() { - - await this.http.get(environment.apiUrl + "/i18n").subscribe({ - next: (data: any) => { - this.locales = data; - }, error: (error) => { } - }); + this.locales = await firstValueFrom(this.http.get(environment.apiUrl + "/i18n")); let browserLocale = window.navigator.language || window.parent.navigator.language; @@ -56,20 +51,14 @@ export class I18nService { locale = this.locales[ 0 ]; } - this.setLocale(locale); - await this.http.get(environment.apiUrl + "/i18n/" + locale).subscribe({ - next: (data: any) => { - this.i18n = data; - }, error: async (error) => { - await this.http.get("/assets/i18n/" + locale + ".json").subscribe({ - next: (data: any) => { - this.i18n = data; - }, error: (error) => { - } - }); - } - }); + try { + this.i18n = await firstValueFrom(this.http.get(environment.apiUrl + "/i18n/" + locale)); + } catch { + this.i18n = await firstValueFrom(this.http.get("/assets/i18n/" + locale + ".json")); + } + + this.setLocale(locale); }