Skip to content

Commit 781b5e8

Browse files
committed
OF version
1 parent c160de9 commit 781b5e8

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/core/classes/lang-loader.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ import { Injectable } from '@angular/core';
1616
import { mergeDeep, TranslateLoader, TranslationObject } from '@ngx-translate/core';
1717
import { Http, Translate } from '@singletons';
1818
import { CoreLogger } from '@singletons/logger';
19-
import { firstValueFrom, Observable, Subject } from 'rxjs';
19+
import { firstValueFrom, Observable, of, Subject } from 'rxjs';
2020

2121
@Injectable()
2222
export class MoodleTranslateLoader implements TranslateLoader {
2323

2424
protected translations: { [lang: string]: TranslationObject } = {};
25-
protected observables: { [lang: string]: Subject<TranslationObject> } = {};
2625

2726
protected customStrings: { [lang: string]: TranslationObject } = {}; // Strings defined using the admin tool.
2827
protected sitePluginsStrings: { [lang: string]: TranslationObject } = {}; // Strings defined by site plugins.
@@ -38,30 +37,30 @@ export class MoodleTranslateLoader implements TranslateLoader {
3837
* @returns Observable resolved with the translations object.
3938
*/
4039
getTranslation(lang: string): Observable<TranslationObject> {
41-
if (this.observables[lang]) {
40+
if (this.translations[lang]) {
4241
this.logger.debug('Get translation', lang);
4342
// This is done here to ensure site strings and custom strings are loaded in the proper order.
4443
const translation = this.mergeTranslation(lang);
4544

46-
this.observables[lang].next(translation);
47-
48-
return this.observables[lang];
45+
return of(translation);
4946
}
5047

51-
this.observables[lang] = new Subject<TranslationObject>();
48+
const observable = new Subject<TranslationObject>();
5249

5350
this.loadLanguage(lang).then((translation) => {
54-
this.observables[lang].next(translation);
51+
observable.next(translation);
52+
observable.complete();
5553

5654
this.logger.debug('Load translation', lang);
5755

5856
return;
5957
}).catch((error) => {
6058
this.logger.error('Error loading translation', lang, error);
61-
this.observables[lang].next({});
59+
observable.next({});
60+
observable.complete();
6261
});
6362

64-
return this.observables[lang];
63+
return observable;
6564
}
6665

6766
/**

0 commit comments

Comments
 (0)