mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Upgrade translation service
This commit is contained in:
@@ -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';
|
||||
|
Reference in New Issue
Block a user