fix offline state, update label

This commit is contained in:
_Bastler
2023-12-15 13:00:25 +01:00
parent 30bed7245f
commit 86af84c7a5
4 changed files with 620 additions and 83 deletions
@@ -12,7 +12,7 @@
<a mat-raised-button color="primary" (click)="retry()">
{{'service-unavailable.retry' | i18n}}
</a>
<a mat-raised-button href="https://wiki.bstly.de/help#Support">
<a mat-raised-button href="https://wiki.bstly.de/help#support">
{{'service-unavailable.support' | i18n}}
</a>
</mat-card-actions>
+19 -16
View File
@@ -11,7 +11,7 @@ import { ActivatedRoute } from '@angular/router';
export class I18nService {
locale: string = "de-informal";
locales: any = [ "de-informal" ];
locales: any = ["en", "de-informal"];
i18n: any;
constructor(private http: HttpClient,
@@ -30,19 +30,22 @@ export class I18nService {
}
async fetch() {
this.locales = await firstValueFrom(this.http.get(environment.apiUrl + "/i18n"));
try {
this.locales = await firstValueFrom(this.http.get(environment.apiUrl + "/i18n"));
} catch {
this.locales = ["en", "de-informal"];
}
let browserLocale = window.navigator.language || window.parent.navigator.language;
if (browserLocale.indexOf("-") != -1) {
browserLocale = browserLocale.split("-")[ 0 ];
browserLocale = browserLocale.split("-")[0];
}
let locale = browserLocale || this.locales[ 0 ];
let locale = browserLocale || this.locales[0];
try {
locale = localStorage.getItem("bstly.locale") || locale;
} catch {
locale = window.location.search.split("locale=")[ 1 ];
locale = window.location.search.split("locale=")[1];
}
if (locale == 'de') {
@@ -50,7 +53,7 @@ export class I18nService {
}
if (this.locales.indexOf(locale) == -1) {
locale = this.locales[ 0 ];
locale = this.locales[0];
}
@@ -75,19 +78,19 @@ export class I18nService {
key += '';
if (!from) {
return empty ? this.empty(key, args, path) : (key || "");
} else if (from[ key ]) {
if (typeof from[ key ] === 'object') {
if (from[ key ][ "." ]) {
return this.insertArguments(from[ key ][ "." ], args);
} else if (from[key]) {
if (typeof from[key] === 'object') {
if (from[key]["."]) {
return this.insertArguments(from[key]["."], args);
}
return empty ? this.empty(key, args, path) : (key || "");
}
return this.insertArguments(from[ key ], args);
return this.insertArguments(from[key], args);
} else {
let keys = key.split(".");
if (from[ keys[ 0 ] ]) {
if (from[keys[0]]) {
key = keys.slice(1, keys.length).join(".");
return this.getInternal(key, args, from[ keys[ 0 ] ], path + keys[ 0 ] + ".", empty)
return this.getInternal(key, args, from[keys[0]], path + keys[0] + ".", empty)
}
}
@@ -101,7 +104,7 @@ export class I18nService {
insertArguments(label: string, args: string[]) {
if (args) {
for (let index in args) {
label = label.replace(`{${index}}`, this.get(args[ index ], null));
label = label.replace(`{${index}}`, this.get(args[index], null));
}
}
return label;
@@ -143,6 +146,6 @@ export class I18nPaginatorIntl implements MatPaginatorIntl {
}
const amountPages = Math.ceil(length / pageSize);
return this.i18n.get('paginator.range', [ page + 1 + "", amountPages + "" ]);
return this.i18n.get('paginator.range', [page + 1 + "", amountPages + ""]);
}
}