[ADF-3630] fix i18n fallback behaviour (#3851)

* fix i18n fallback behaviour

* update tests

* update tests

* configuration fixes

* test configuration fix
This commit is contained in:
Denys Vuika
2018-10-04 10:11:30 +01:00
committed by Eugenio Romano
parent d1f87837ac
commit 54cca45ec1
12 changed files with 126 additions and 92 deletions

View File

@@ -62,22 +62,29 @@ export class TranslationService {
addTranslationFolder(name: string = '', path: string = '') {
if (!this.customLoader.providerRegistered(name)) {
this.customLoader.registerProvider(name, path);
if (this.userLang) {
this.translate.getTranslation(this.userLang).subscribe(() => {
this.translate.use(this.userLang);
this.onTranslationChanged(this.userLang);
}
);
this.loadTranslation(this.userLang, this.defaultLang);
} else {
this.translate.getTranslation(this.defaultLang).subscribe(() => {
this.translate.use(this.defaultLang);
this.onTranslationChanged(this.defaultLang);
}
);
this.loadTranslation(this.defaultLang);
}
}
}
loadTranslation(lang: string, fallback?: string) {
this.translate.getTranslation(lang).subscribe(
() => {
this.translate.use(lang);
this.onTranslationChanged(lang);
},
() => {
if (fallback && fallback !== lang) {
this.loadTranslation(fallback);
}
}
);
}
/**
* Triggers a notification callback when the translation language changes.
* @param lang The new language code