mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Improved AlfrescoTranslationService
This commit is contained in:
@@ -79,10 +79,10 @@ export class AppComponent {
|
|||||||
let userLang = navigator.language.split('-')[0]; // use navigator lang if available
|
let userLang = navigator.language.split('-')[0]; // use navigator lang if available
|
||||||
userLang = /(fr|en)/gi.test(userLang) ? userLang : 'en';
|
userLang = /(fr|en)/gi.test(userLang) ? userLang : 'en';
|
||||||
|
|
||||||
// this language will be used as a fallback when a translation isn't found in the current language
|
|
||||||
this.translate.setDefaultLang('en');
|
this.translate.setDefaultLang('en');
|
||||||
|
|
||||||
// the lang to use, if the lang isn't available, it will use the current loader to get them
|
this.translate.currentLoader.addComponentList('');
|
||||||
|
this.translate.getTranslation(userLang);
|
||||||
this.translate.use(userLang);
|
this.translate.use(userLang);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,23 +25,30 @@ export class AlfrescoTranslationLoader implements TranslateLoader {
|
|||||||
|
|
||||||
private prefix: string = 'i18n';
|
private prefix: string = 'i18n';
|
||||||
private suffix: string = '.json';
|
private suffix: string = '.json';
|
||||||
|
private _componentList: string[] = [];
|
||||||
|
|
||||||
constructor(private http: Http) {
|
constructor(private http: Http) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addComponentList(name: string) {
|
||||||
|
this._componentList.push(name);
|
||||||
|
}
|
||||||
|
|
||||||
getTranslation(lang: string): Observable<any> {
|
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 => {
|
return Observable.create(observer => {
|
||||||
Observable.forkJoin(
|
Observable.forkJoin(observableBatch).subscribe(
|
||||||
this.http.get(`${this.prefix}/${lang}${this.suffix}`).map((res: Response) => res.json()),
|
translations => {
|
||||||
this.http.get('node_modules/ng2-alfresco-upload/' +
|
let multiLanguage = '' ;
|
||||||
`${this.prefix}/${lang}${this.suffix}`).map((res: Response) => res.json()),
|
translations.forEach((translate) => {
|
||||||
this.http.get('node_modules/ng2-alfresco-login/' +
|
multiLanguage += JSON.stringify(translate);
|
||||||
`${this.prefix}/${lang}${this.suffix}`).map((res: Response) => res.json())
|
});
|
||||||
).subscribe(
|
observer.next(JSON.parse(multiLanguage.replace(/}{/g, '','')));
|
||||||
data => {
|
|
||||||
let multiLanguage = JSON.parse((JSON.stringify(data[0])
|
|
||||||
+ JSON.stringify(data[1])
|
|
||||||
+ JSON.stringify(data[2])).replace(/}{/g, ','));
|
|
||||||
observer.next(multiLanguage);
|
observer.next(multiLanguage);
|
||||||
observer.complete();
|
observer.complete();
|
||||||
});
|
});
|
||||||
|
@@ -167,7 +167,8 @@ export class AlfrescoLoginComponent {
|
|||||||
userLang = /(fr|en)/gi.test(userLang) ? userLang : 'en';
|
userLang = /(fr|en)/gi.test(userLang) ? userLang : 'en';
|
||||||
|
|
||||||
this.translate.setDefaultLang(userLang);
|
this.translate.setDefaultLang(userLang);
|
||||||
|
this.translate.currentLoader.addComponentList('node_modules/ng2-alfresco-login');
|
||||||
|
this.translate.getTranslation(userLang);
|
||||||
this.translate.use(userLang);
|
this.translate.use(userLang);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -141,7 +141,8 @@ export class UploadButtonComponent {
|
|||||||
userLang = /(fr|en)/gi.test(userLang) ? userLang : 'en';
|
userLang = /(fr|en)/gi.test(userLang) ? userLang : 'en';
|
||||||
|
|
||||||
this.translate.setDefaultLang(userLang);
|
this.translate.setDefaultLang(userLang);
|
||||||
|
this.translate.currentLoader.addComponentList('node_modules/ng2-alfresco-upload');
|
||||||
|
this.translate.getTranslation(userLang);
|
||||||
this.translate.use(userLang);
|
this.translate.use(userLang);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user