Improve i18n service (#15215)

Signed-off-by: AllForNothing <sshijun@vmware.com>
This commit is contained in:
孙世军 2021-06-30 10:22:48 +08:00 committed by GitHub
parent f902db9d85
commit 91f4d412f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 29 deletions

View File

@ -73,16 +73,6 @@ export class AppComponent {
});
}
initLanguage() {
/**
* due to the bug(https://github.com/ngx-translate/core/issues/1258) of translate module
* we have to call use method for all supported languages
* use method will load related language json from backend server
*/
const usedLangs: Array<Observable<any>> = [];
supportedLangs.forEach(lang => {
usedLangs.push(this.translate.use(lang));
});
forkJoin(usedLangs).subscribe(() => { // use target lang after all langs json loaded
this.translate.addLangs(supportedLangs);
this.translate.setDefaultLang(DeFaultLang);
let selectedLang: string = DeFaultLang;
@ -101,8 +91,7 @@ export class AppComponent {
}
}
localStorage.setItem(DEFAULT_LANG_LOCALSTORAGE_KEY, selectedLang);
// use method will load related language json from backend server
this.translate.use(selectedLang);
}
);
}
}

View File

@ -149,7 +149,9 @@ export class NavigatorComponent implements OnInit {
switchLanguage(lang: string): void {
this.selectedLang = lang;
localStorage.setItem(DEFAULT_LANG_LOCALSTORAGE_KEY, lang);
this.translate.use(lang);
// due to the bug(https://github.com/ngx-translate/core/issues/1258) of translate module
// have to reload
this.translate.use(lang).subscribe(() => window.location.reload());
}
// Handle the home action