This commit is contained in:
_Bastler 2022-03-20 13:32:10 +01:00
parent d68060b3fb
commit bb857d58cc
2 changed files with 11 additions and 24 deletions

View File

@ -69,9 +69,7 @@ import { JukeboxComponent } from './pages/jukebox/jukebox.compontent';
export function init_app(i18n: I18nService) { export function init_app(i18n: I18nService) {
return () => { return () => i18n.fetch()
i18n.fetch();
};
} }
@Injectable() @Injectable()

View File

@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { environment } from '../../environments/environment'; import { environment } from '../../environments/environment';
import { MatPaginatorIntl } from '@angular/material/paginator'; import { MatPaginatorIntl } from '@angular/material/paginator';
import { Subject } from 'rxjs'; import { Subject, firstValueFrom } from 'rxjs';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
@ -10,7 +10,7 @@ import { Subject } from 'rxjs';
export class I18nService { export class I18nService {
locale: string = "de-informal"; locale: string = "de-informal";
locales: any[] = [ "de-informal" ]; locales: any = [ "de-informal" ];
i18n: any; i18n: any;
constructor(private http: HttpClient) { constructor(private http: HttpClient) {
@ -30,12 +30,7 @@ export class I18nService {
} }
async fetch() { async fetch() {
this.locales = await firstValueFrom(this.http.get(environment.apiUrl + "/i18n"));
await this.http.get(environment.apiUrl + "/i18n").subscribe({
next: (data: any) => {
this.locales = data;
}, error: (error) => { }
});
let browserLocale = window.navigator.language || window.parent.navigator.language; let browserLocale = window.navigator.language || window.parent.navigator.language;
@ -56,20 +51,14 @@ export class I18nService {
locale = this.locales[ 0 ]; locale = this.locales[ 0 ];
} }
this.setLocale(locale);
await this.http.get(environment.apiUrl + "/i18n/" + locale).subscribe({ try {
next: (data: any) => { this.i18n = await firstValueFrom(this.http.get(environment.apiUrl + "/i18n/" + locale));
this.i18n = data; } catch {
}, error: async (error) => { this.i18n = await firstValueFrom(this.http.get("/assets/i18n/" + locale + ".json"));
await this.http.get("/assets/i18n/" + locale + ".json").subscribe({
next: (data: any) => {
this.i18n = data;
}, error: (error) => {
} }
}); this.setLocale(locale);
}
});
} }