-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHttpTranlateLoader.ts
41 lines (36 loc) · 1.27 KB
/
HttpTranlateLoader.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {Injectable} from '@angular/core';
import {TranslateLoader} from '@ngx-translate/core';
import {HttpClient} from '@angular/common/http';
import {RuntimeConfigLoaderService} from '../runtime-config-loader/runtime-config-loader-lib.service';
import {Observable} from 'rxjs/Observable';
@Injectable()
export class TranslateBrowserLoader implements TranslateLoader {
constructor(private http: HttpClient, private appConfigLoader: RuntimeConfigLoaderService) {
}
getTranslation(lang: string): Observable<any> {
return Observable.create(observer => {
let appConfig = this.appConfigLoader.getConfig();
let result;
if (appConfig) {
this.http.get(`${appConfig.ssr.symphonyApiUrl}/cms/locale/${lang}.json`).subscribe(
(translate) => {
result = translate;
observer.next(result);
observer.complete();
}
);
} else {
this.appConfigLoader.configSubject.subscribe((res) => {
appConfig = res;
this.http.get(`${appConfig.ssr.symphonyApiUrl}/cms/locale/${lang}.json`).subscribe(
(translate) => {
result = translate;
observer.next(result);
observer.complete();
}
);
});
}
});
}
}