Merge pull request #2146 from dpalou/MOBILE-3189

MOBILE-3189 lang: Emit onLangChange when custom strings loaded
main
Juan Leyva 2019-11-08 11:30:17 +01:00 committed by GitHub
commit 57b6861606
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 0 deletions

View File

@ -315,6 +315,8 @@ export class CoreLangProvider {
return;
}
let currentLangChanged = false;
const list: string[] = strings.split(/(?:\r\n|\r|\n)/);
list.forEach((entry: string) => {
const values: string[] = entry.split('|');
@ -327,6 +329,10 @@ export class CoreLangProvider {
lang = values[2].replace(/_/g, '-'); // Use the app format instead of Moodle format.
if (lang == this.currentLanguage) {
currentLangChanged = true;
}
if (!this.customStrings[lang]) {
this.customStrings[lang] = {};
}
@ -340,6 +346,14 @@ export class CoreLangProvider {
});
this.customStringsRaw = strings;
if (currentLangChanged) {
// Some lang strings have changed, emit an event to update the pipes.
this.translate.onLangChange.emit({
lang: this.currentLanguage,
translations: this.translate.translations[this.currentLanguage]
});
}
}
/**