Improved AlfrescoTranslationService

This commit is contained in:
mauriziovitale84
2016-05-19 15:47:05 +01:00
parent 5cb3610888
commit ca6d5725e9
4 changed files with 24 additions and 15 deletions

View File

@@ -25,23 +25,30 @@ export class AlfrescoTranslationLoader implements TranslateLoader {
private prefix: string = 'i18n';
private suffix: string = '.json';
private _componentList: string[] = [];
constructor(private http: Http) {
}
addComponentList(name: string) {
this._componentList.push(name);
}
getTranslation(lang: string): Observable<any> {
let observableBatch = [];
this._componentList.forEach((component) => {
observableBatch.push(this.http.get(`${component}/${this.prefix}/${lang}${this.suffix}`).map((res: Response) => res.json()))
});
return Observable.create(observer => {
Observable.forkJoin(
this.http.get(`${this.prefix}/${lang}${this.suffix}`).map((res: Response) => res.json()),
this.http.get('node_modules/ng2-alfresco-upload/' +
`${this.prefix}/${lang}${this.suffix}`).map((res: Response) => res.json()),
this.http.get('node_modules/ng2-alfresco-login/' +
`${this.prefix}/${lang}${this.suffix}`).map((res: Response) => res.json())
).subscribe(
data => {
let multiLanguage = JSON.parse((JSON.stringify(data[0])
+ JSON.stringify(data[1])
+ JSON.stringify(data[2])).replace(/}{/g, ','));
Observable.forkJoin(observableBatch).subscribe(
translations => {
let multiLanguage = '' ;
translations.forEach((translate) => {
multiLanguage += JSON.stringify(translate);
});
observer.next(JSON.parse(multiLanguage.replace(/}{/g, '','')));
observer.next(multiLanguage);
observer.complete();
});