fix translate

This commit is contained in:
Mario Romano
2016-05-19 19:39:13 +01:00
parent 40d8cff331
commit 3e54eaf5fe
22 changed files with 172 additions and 108 deletions

View File

@@ -0,0 +1,14 @@
npm-debug.log
.idea
assets/
coverage/
demo/
node_modules
typings/
src/
/ng2-alfresco-upload.ts
/ng2-alfresco-upload.d.ts
/ng2-alfresco-upload.js
/ng2-alfresco-upload.js.map

View File

@@ -1,7 +1,7 @@
{
"name": "ng2-alfresco-core",
"description": "Alfresco Angular 2 Components core",
"version": "0.1.11",
"version": "0.1.12",
"author": "Alfresco Software, Ltd.",
"scripts": {
"typings": "typings install",

View File

@@ -16,20 +16,29 @@
*/
import {AlfrescoSettingsService} from './services/AlfrescoSettingsService';
import {AlfrescoTranslationLoader} from './services/AlfrescoTranslationService';
export * from './services/AlfrescoSettingsService';
export * from './services/AlfrescoTranslationService';
import {AlfrescoSettingsService} from './services/AlfrescoSettingsService.service';
import {AlfrescoTranslationLoader} from './services/AlfrescoTranslationLoader.service';
import {AlfrescoTranslationService} from './services/AlfrescoTranslationService.service';
import {AlfrescoPipeTranslate} from './services/AlfrescoPipeTranslate.service';
export * from './services/AlfrescoSettingsService.service';
export * from './services/AlfrescoTranslationLoader.service';
export * from './services/AlfrescoTranslationService.service';
export * from './services/AlfrescoPipeTranslate.service';
export default {
directives: [],
providers: [
AlfrescoSettingsService,
AlfrescoTranslationLoader
AlfrescoTranslationLoader,
AlfrescoTranslationService,
AlfrescoPipeTranslate
]
};
export const ALFRESCO_CORE_PROVIDERS: [any] = [
AlfrescoSettingsService,
AlfrescoTranslationLoader
AlfrescoTranslationLoader,
AlfrescoTranslationService,
AlfrescoPipeTranslate
];

View File

@@ -0,0 +1,32 @@
/*!
* @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 'angular2/core';
import { TranslatePipe } from 'ng2-translate/ng2-translate';
import { AlfrescoTranslationService } from './AlfrescoTranslationService.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);
}
}

View File

@@ -16,9 +16,9 @@
*/
import { Injectable } from 'angular2/core';
import { Http, Response } from 'angular2/http';
import { TranslateLoader } from 'ng2-translate/ng2-translate';
import { Response, Http } from 'angular2/http';
import { Observable } from 'rxjs/Observable';
import { TranslateLoader } from 'ng2-translate/ng2-translate';
@Injectable()
export class AlfrescoTranslationLoader implements TranslateLoader {
@@ -45,11 +45,11 @@ export class AlfrescoTranslationLoader implements TranslateLoader {
return Observable.create(observer => {
Observable.forkJoin(observableBatch).subscribe(
(translations: any[]) => {
let multiLanguage:any = '';
let multiLanguage: any = '';
translations.forEach((translate) => {
multiLanguage += JSON.stringify(translate);
});
observer.next(JSON.parse(multiLanguage.replace(/}{/g, '', '')));
observer.next(JSON.parse(multiLanguage.replace(/}{/g, ',')));
observer.next(multiLanguage);
observer.complete();
});

View File

@@ -0,0 +1,41 @@
/*!
* @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, Optional } from 'angular2/core';
import { Http } from 'angular2/http';
import { MissingTranslationHandler, TranslateService } from 'ng2-translate/ng2-translate';
import { AlfrescoTranslationLoader } from './AlfrescoTranslationLoader.service';
@Injectable()
export class AlfrescoTranslationService extends TranslateService {
currentLoader: AlfrescoTranslationLoader;
constructor(http: Http, currentLoader: AlfrescoTranslationLoader, @Optional() missingTranslationHandler: MissingTranslationHandler) {
super(http, currentLoader, missingTranslationHandler);
}
translationInit(path: string): void {
let userLang = navigator.language.split('-')[0]; // use navigator lang if available
userLang = /(fr|en)/gi.test(userLang) ? userLang : 'en';
this.setDefaultLang(userLang);
this.currentLoader.addComponentList(path);
this.getTranslation(userLang);
this.use(userLang);
}
}