added locale backup + en support

This commit is contained in:
_Bastler
2021-03-26 10:17:28 +01:00
parent a9fd56efc6
commit 34755be840
16 changed files with 2724 additions and 1039 deletions
+17 -10
View File
@@ -1,18 +1,18 @@
import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import { environment } from '../../environments/environment';
import {environment} from '../../environments/environment';
@Injectable({
providedIn: 'root',
})
export class I18nService {
locale: string;
locales : any = ["de-informal"];
locale: string = "de-informal";
locales: any = ["de-informal"];
i18n: any;
constructor(private http: HttpClient) {
}
getLocales() {
@@ -28,29 +28,36 @@ export class I18nService {
}
async fetch() {
let browserLocale = navigator.language;
if(browserLocale.indexOf("-") != -1) {
browserLocale = browserLocale.split("-")[0];
}
let locale = localStorage.getItem("bstly.locale") || browserLocale || this.locales[0];
let locale = localStorage.getItem("bstly.locale") || browserLocale || this.locales[0];
if(locale == 'de') {
locale = 'de-informal';
}
this.locales = await this.http.get(environment.apiUrl + "/i18n").toPromise();
try {
this.locales = await this.http.get(environment.apiUrl + "/i18n").toPromise();
} catch(e) {
console.debug("fallback to default locales");
}
if(this.locales.indexOf(locale) == -1) {
locale = this.locales[0];
}
this.setLocale(locale);
this.i18n = await this.http.get(environment.apiUrl + "/i18n/" + locale).toPromise();
try {
this.i18n = await this.http.get(environment.apiUrl + "/i18n/" + locale).toPromise();
} catch(e) {
this.i18n = await this.http.get("/assets/i18n/" + locale + ".json").toPromise();
console.debug("fallback to default locale");
}
}
get(key, args: string[]): string {