mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
Refactor language import in I18nService
This commit is contained in:
@@ -33,9 +33,9 @@ export class I18nService {
|
||||
filter(l => !!l),
|
||||
distinctUntilChanged()
|
||||
)
|
||||
.subscribe(lang => {
|
||||
.subscribe(async lang => {
|
||||
this.cache.clear();
|
||||
this.dictionary = require(`../../../assets/jsons/translations/${lang.split("-")[0]}.json`);
|
||||
this.dictionary = this.importLang([lang, lang.split("-")[0]], "en");
|
||||
|
||||
i18n.dayNames = getProperty(this.dictionary, "dateformat.dayNames");
|
||||
i18n.monthNames = getProperty(this.dictionary, "dateformat.monthNames");
|
||||
@@ -43,6 +43,20 @@ export class I18nService {
|
||||
});
|
||||
}
|
||||
|
||||
private importLang(lang: string[], fallback: string): Record<string, string> {
|
||||
|
||||
for (const l of lang) {
|
||||
try {
|
||||
return require(`../../../assets/jsons/translations/${l.toLowerCase()}.json`);
|
||||
}
|
||||
catch (e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return require(`../../../assets/jsons/translations/${fallback.toLowerCase()}.json`);
|
||||
}
|
||||
|
||||
public getSupportedLanguages(): string[] {
|
||||
return this.configService.get("supported_languages" as DefaultConfigKey);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user