mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
Upgrade translation service
This commit is contained in:
parent
6104c5d669
commit
d1bae40d0d
@ -20,7 +20,7 @@ import { HttpModule } from '@angular/http';
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
|
||||
import { TranslateModule } from 'ng2-translate/ng2-translate';
|
||||
import { TranslateModule, TranslateLoader } from 'ng2-translate/ng2-translate';
|
||||
import { SearchModule } from 'ng2-alfresco-search';
|
||||
import { LoginModule } from 'ng2-alfresco-login';
|
||||
|
||||
@ -39,6 +39,8 @@ import { VIEWERCOMPONENT } from 'ng2-alfresco-viewer';
|
||||
import { TAGCOMPONENT, TAGSERVICES } from 'ng2-alfresco-tag';
|
||||
import { WEBSCRIPTCOMPONENT } from 'ng2-alfresco-webscript';
|
||||
|
||||
import { AlfrescoTranslationLoader } from 'ng2-alfresco-core';
|
||||
import { Http } from '@angular/http';
|
||||
|
||||
import {
|
||||
UploadButtonComponent,
|
||||
@ -101,7 +103,11 @@ const ACTIVITI_FORM_DIRECTIVES: any[] = [
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
HttpModule,
|
||||
TranslateModule.forRoot(),
|
||||
TranslateModule.forRoot({
|
||||
provide: TranslateLoader,
|
||||
useFactory: (http: Http) => new AlfrescoTranslationLoader(http),
|
||||
deps: [Http]
|
||||
}),
|
||||
routing,
|
||||
LoginModule,
|
||||
SearchModule.forRoot()
|
||||
|
@ -1,32 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Injectable, ChangeDetectorRef, Pipe } from '@angular/core';
|
||||
import { TranslatePipe } from 'ng2-translate/ng2-translate';
|
||||
import { AlfrescoTranslationService } from './AlfrescoTranslation.service';
|
||||
|
||||
@Injectable()
|
||||
@Pipe({
|
||||
name: 'translate',
|
||||
pure: false // required to update the value when the promise is resolved
|
||||
})
|
||||
export class AlfrescoPipeTranslate extends TranslatePipe {
|
||||
|
||||
constructor(translate: AlfrescoTranslationService, _ref: ChangeDetectorRef) {
|
||||
super(translate, _ref);
|
||||
}
|
||||
}
|
@ -15,26 +15,31 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Injectable, Optional } from '@angular/core';
|
||||
import { MissingTranslationHandler, TranslateService } from 'ng2-translate/ng2-translate';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { TranslateService } from 'ng2-translate/ng2-translate';
|
||||
import { AlfrescoTranslationLoader } from './AlfrescoTranslationLoader.service';
|
||||
|
||||
@Injectable()
|
||||
export class AlfrescoTranslationService extends TranslateService {
|
||||
export class AlfrescoTranslationService {
|
||||
userLang: string = 'en' ;
|
||||
|
||||
constructor(public currentLoader: AlfrescoTranslationLoader, @Optional() missingTranslationHandler: MissingTranslationHandler) {
|
||||
super(currentLoader, missingTranslationHandler);
|
||||
constructor(private translate: TranslateService) {
|
||||
this.userLang = navigator.language.split('-')[0]; // use navigator lang if available
|
||||
this.userLang = /(fr|en)/gi.test(this.userLang) ? this.userLang : 'en';
|
||||
this.setDefaultLang(this.userLang);
|
||||
translate.setDefaultLang(this.userLang);
|
||||
}
|
||||
|
||||
addTranslationFolder(name: string = '') {
|
||||
if (!this.currentLoader.existComponent(name)) {
|
||||
this.currentLoader.addComponentList(name);
|
||||
this.getTranslation(this.userLang);
|
||||
let loader = <AlfrescoTranslationLoader> this.translate.currentLoader;
|
||||
if (!loader.existComponent(name)) {
|
||||
loader.addComponentList(name);
|
||||
this.translate.getTranslation(this.userLang);
|
||||
}
|
||||
this.use(this.userLang);
|
||||
this.translate.use(this.userLang);
|
||||
}
|
||||
|
||||
use(lang: string): Observable<any> {
|
||||
return this.translate.use(lang);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ export * from './AlfrescoApi.service';
|
||||
export * from './AlfrescoSettings.service';
|
||||
export * from './AlfrescoTranslationLoader.service';
|
||||
export * from './AlfrescoTranslation.service';
|
||||
export * from './AlfrescoPipeTranslate.service';
|
||||
export * from './AlfrescoAuthentication.service';
|
||||
export * from './AlfrescoContent.service';
|
||||
export * from './renditions.service';
|
||||
|
Loading…
x
Reference in New Issue
Block a user