Skip to content

Commit

Permalink
core(TranslateService): load translations if they have not been loade…
Browse files Browse the repository at this point in the history
  • Loading branch information
dfmeretzki committed Jan 19, 2022
1 parent 5d04bd8 commit dff8b87
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions projects/ngx-translate/core/src/lib/translate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ export class TranslateService {
*/
public use(lang: string): Observable<any> {
// don't change the language if the language given is already selected
let changeLang = true;
if (lang === this.currentLang) {
return of(this.translations[lang]);
changeLang = false;
}

let pending = this.retrieveTranslations(lang);
Expand All @@ -216,12 +217,16 @@ export class TranslateService {

pending.pipe(take(1))
.subscribe((res: any) => {
this.changeLang(lang);
if (changeLang) {
this.changeLang(lang);
}
});

return pending;
} else { // we have this language, return an Observable
this.changeLang(lang);
if (changeLang) {
this.changeLang(lang);
}

return of(this.translations[lang]);
}
Expand Down

0 comments on commit dff8b87

Please sign in to comment.