Fixed translation service

This commit is contained in:
mauriziovitale84
2016-05-20 17:22:58 +01:00
parent 55c766e74b
commit 9c9c4fbba2
5 changed files with 53 additions and 11 deletions

View File

@@ -44,7 +44,7 @@ declare var document: any;
{path: '/search', name: 'Search', component: AlfrescoSearchComponent} {path: '/search', name: 'Search', component: AlfrescoSearchComponent}
]) ])
export class AppComponent { export class AppComponent {
translate: TranslateService; translate: AlfrescoTranslationService;
searchForm: ControlGroup; searchForm: ControlGroup;
constructor(private _fb: FormBuilder, constructor(private _fb: FormBuilder,
@@ -58,7 +58,8 @@ export class AppComponent {
searchTerm: ['', Validators.compose([Validators.required, Validators.minLength(3)])] searchTerm: ['', Validators.compose([Validators.required, Validators.minLength(3)])]
}); });
translate.translationInit(''); this.translate = translate;
this.translate.translationInit();
} }
isActive(instruction: any[]): boolean { isActive(instruction: any[]): boolean {

View File

@@ -1,3 +1,41 @@
{ {
"title" : "Benvenuto" "title" : "Benvenuto"
}
"DOCUMENT_LIST": {
"COLUMNS": {
"DISPLAY_NAME": "Mostra name",
"CREATED_BY": "Creato da",
"CREATED_ON": "Creato il"
},
"ACTIONS": {
"FOLDER": {
"SYSTEM_1": "Azione 1 di sistema sulla cartella",
"CUSTOM": "Azione personalizzata su cartella"
},
"DOCUMENT": {
"DOWNLOAD": "Download",
"SYSTEM_2": "System document action 2",
"CUSTOM": "Custom action"
}
}
},
"DATATABLE": {
"COLUMNS": {
"DISPLAY_NAME": "Display name",
"CREATED_BY": "Created by",
"CREATED_ON": "Created on"
},
"ACTIONS": {
"FOLDER": {
"SYSTEM_1": "System folder action 1",
"CUSTOM": "Custom folder action"
},
"DOCUMENT": {
"DOWNLOAD": "Download",
"SYSTEM_2": "System document action 2",
"CUSTOM": "Custom action"
}
}
}
}

View File

@@ -50,7 +50,6 @@ export class AlfrescoTranslationLoader implements TranslateLoader {
multiLanguage += JSON.stringify(translate); multiLanguage += JSON.stringify(translate);
}); });
observer.next(JSON.parse(multiLanguage.replace(/}{/g, ','))); observer.next(JSON.parse(multiLanguage.replace(/}{/g, ',')));
observer.next(multiLanguage);
observer.complete(); observer.complete();
}); });
}); });

View File

@@ -22,20 +22,24 @@ import { AlfrescoTranslationLoader } from './AlfrescoTranslationLoader.service';
@Injectable() @Injectable()
export class AlfrescoTranslationService extends TranslateService { export class AlfrescoTranslationService extends TranslateService {
userLang: string;
currentLoader: AlfrescoTranslationLoader; currentLoader: AlfrescoTranslationLoader;
constructor(http: Http, currentLoader: AlfrescoTranslationLoader, @Optional() missingTranslationHandler: MissingTranslationHandler) { constructor(http: Http, currentLoader: AlfrescoTranslationLoader, @Optional() missingTranslationHandler: MissingTranslationHandler) {
super(http, currentLoader, missingTranslationHandler); super(http, currentLoader, missingTranslationHandler);
} }
translationInit(path: string): void { translationInit(name: string = ''): void {
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.userLang = userLang;
this.setDefaultLang(this.userLang);
this.addComponent(name);
this.use(this.userLang);
}
this.setDefaultLang(userLang); addComponent(name: string) {
this.currentLoader.addComponentList(path); this.currentLoader.addComponentList(name);
this.getTranslation(userLang); this.getTranslation(this.userLang);
this.use(userLang);
} }
} }

View File

@@ -106,7 +106,7 @@ export class UploadButtonComponent {
} }
}); });
translate.translationInit('node_modules/ng2-alfresco-upload'); translate.addComponent('node_modules/ng2-alfresco-upload');
} }
/** /**