diff --git a/demo-shell-ng2/app/app.module.ts b/demo-shell-ng2/app/app.module.ts index 933d484f3c..7047e9c47a 100644 --- a/demo-shell-ng2/app/app.module.ts +++ b/demo-shell-ng2/app/app.module.ts @@ -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() diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoPipeTranslate.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoPipeTranslate.service.ts deleted file mode 100644 index 12ba8b9b7f..0000000000 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoPipeTranslate.service.ts +++ /dev/null @@ -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); - } -} diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoTranslation.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoTranslation.service.ts index a63322914e..7927328191 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoTranslation.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoTranslation.service.ts @@ -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 = 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 { + return this.translate.use(lang); } } diff --git a/ng2-components/ng2-alfresco-core/src/services/index.ts b/ng2-components/ng2-alfresco-core/src/services/index.ts index c5eb956dc8..b17ea23c9a 100644 --- a/ng2-components/ng2-alfresco-core/src/services/index.ts +++ b/ng2-components/ng2-alfresco-core/src/services/index.ts @@ -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';