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);
}
}

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

@@ -20,19 +20,14 @@ import {MyLoginComponent} from './components/my-login.component';
import {ALFRESCO_AUTHENTICATION} from 'ng2-alfresco-login/ng2-alfresco-login';
import {ROUTER_PROVIDERS} from 'angular2/router';
import {provide} from 'angular2/core';
import {Http} from 'angular2/http';
import {HTTP_PROVIDERS} from 'angular2/http';
import {TranslateService, TranslateLoader, TranslateStaticLoader} from 'ng2-translate/ng2-translate';
import {ALFRESCO_CORE_PROVIDERS} from 'ng2-alfresco-core/services';
import {TranslateService, TranslateLoader} from 'ng2-translate/ng2-translate';
import {ALFRESCO_CORE_PROVIDERS, AlfrescoTranslationService} from 'ng2-alfresco-core/services';
bootstrap(MyLoginComponent, [
ROUTER_PROVIDERS,
HTTP_PROVIDERS,
provide(TranslateLoader, {
useFactory: (http: Http) => new TranslateStaticLoader(http, 'node_modules/ng2-alfresco-login/i18n', '.json'),
deps: [Http]
}),
// use TranslateService here, and not TRANSLATE_PROVIDERS (which will define a default TranslateStaticLoader)
provide(TranslateLoader, {useClass: AlfrescoTranslationService}),
TranslateService,
ALFRESCO_AUTHENTICATION,
ALFRESCO_CORE_PROVIDERS

View File

@@ -1,7 +1,7 @@
{
"name": "ng2-alfresco-login",
"description": "Alfresco Angular2 Login Component",
"version": "0.1.3",
"version": "0.1.4",
"author": "Alfresco Software, Ltd.",
"scripts": {
"typings": "typings install",
@@ -57,13 +57,13 @@
],
"dependencies": {
"angular2": "2.0.0-beta.15",
"systemjs": "0.19.26",
"es6-shim": "^0.35.0",
"es6-module-loader": "^0.17.8",
"es6-shim": "^0.35.0",
"ng2-alfresco-core": "^0.1.7",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2",
"zone.js": "^0.6.12",
"ng2-translate": "^1.11.2"
"systemjs": "0.19.26",
"zone.js": "^0.6.12"
},
"peerDependencies": {
"angular2": "2.0.0-beta.15"

View File

@@ -19,7 +19,7 @@ import { Component, Output, EventEmitter } from 'angular2/core';
import { Router, ROUTER_DIRECTIVES } from 'angular2/router';
import { FORM_DIRECTIVES, ControlGroup, FormBuilder, Validators } from 'angular2/common';
import { AlfrescoAuthenticationService } from './../services/alfresco-authentication.service';
import { TranslateService, TranslatePipe } from 'ng2-translate/ng2-translate';
import { AlfrescoTranslationService, AlfrescoPipeTranslate } from 'ng2-alfresco-core/services';
declare let componentHandler: any;
declare let __moduleName: string;
@@ -29,7 +29,7 @@ declare let __moduleName: string;
directives: [ROUTER_DIRECTIVES, FORM_DIRECTIVES],
templateUrl: './alfresco-login.component.html',
styleUrls: ['./alfresco-login.component.css'],
pipes: [TranslatePipe]
pipes: [AlfrescoPipeTranslate]
})
export class AlfrescoLoginComponent {
@@ -37,7 +37,6 @@ export class AlfrescoLoginComponent {
onSuccess = new EventEmitter();
@Output()
onError = new EventEmitter();
translate: TranslateService;
form: ControlGroup;
error: boolean = false;
@@ -57,7 +56,7 @@ export class AlfrescoLoginComponent {
constructor(private _fb: FormBuilder,
public auth: AlfrescoAuthenticationService,
public router: Router,
translate: TranslateService) {
private translate: AlfrescoTranslationService) {
this.formError = {
'username': '',
@@ -79,6 +78,8 @@ export class AlfrescoLoginComponent {
}
};
translate.translationInit('node_modules/ng2-alfresco-login');
this.form.valueChanges.subscribe(data => this.onValueChanged(data));
this.onValueChanged(null);

View File

@@ -1,7 +1,7 @@
{
"name": "ng2-alfresco-upload",
"description": "Alfresco Angular2 Upload Component",
"version": "0.1.2",
"version": "0.1.3",
"author": "Alfresco Software, Ltd.",
"scripts": {
"typings": "typings install",
@@ -51,7 +51,6 @@
"es6-module-loader": "^0.17.8",
"es6-shim": "^0.35.0",
"ng2-alfresco-core": "^0.1.0",
"ng2-translate": "^1.11.2",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2",
"systemjs": "0.19.26",

View File

@@ -18,7 +18,7 @@
import { Component, ElementRef, Input } from 'angular2/core';
import { FileModel } from '../models/file.model';
import { FileUploadingListComponent } from './file-uploading-list.component';
import { TranslatePipe } from 'ng2-translate/ng2-translate';
import { AlfrescoPipeTranslate } from 'ng2-alfresco-core/services';
declare let __moduleName: string;
@@ -40,7 +40,7 @@ declare let __moduleName: string;
templateUrl: './file-uploading-dialog.component.html',
styleUrls: ['./file-uploading-dialog.component.css'],
host: {'[class.dialog-show]': 'toggleShowDialog'},
pipes: [TranslatePipe]
pipes: [AlfrescoPipeTranslate]
})
export class FileUploadingDialogComponent {

View File

@@ -18,7 +18,7 @@
import { Component, ElementRef, Input } from 'angular2/core';
import { FileModel } from '../models/file.model';
import { TranslatePipe } from 'ng2-translate/ng2-translate';
import { AlfrescoPipeTranslate } from 'ng2-alfresco-core/services';
declare let __moduleName: string;
@@ -37,7 +37,7 @@ declare let __moduleName: string;
moduleId: __moduleName,
templateUrl: './file-uploading-list.component.html',
styleUrls: ['./file-uploading-list.component.css'],
pipes: [TranslatePipe]
pipes: [AlfrescoPipeTranslate]
})
export class FileUploadingListComponent {

View File

@@ -20,7 +20,7 @@ import { Component, ViewChild, ElementRef, Input, Output, EventEmitter, Optional
import { UploadService } from '../services/upload.service';
import { FileModel } from '../models/file.model';
import { FileUploadingDialogComponent } from './file-uploading-dialog.component';
import { TranslateService, TranslatePipe } from 'ng2-translate/ng2-translate';
import { AlfrescoTranslationService, AlfrescoPipeTranslate } from 'ng2-alfresco-core/services';
import 'rxjs/Rx';
declare let componentHandler: any;
@@ -51,7 +51,7 @@ declare let __moduleName: string;
directives: [FileUploadingDialogComponent],
templateUrl: './upload-button.component.html',
styleUrls: ['./upload-button.component.css'],
pipes: [TranslatePipe]
pipes: [AlfrescoPipeTranslate]
})
export class UploadButtonComponent {
@@ -87,12 +87,12 @@ export class UploadButtonComponent {
filesUploadingList: FileModel [] = [];
translate: TranslateService;
translate: AlfrescoTranslationService;
private _uploaderService: UploadService;
constructor(public el: ElementRef,
@Optional() translate: TranslateService) {
@Optional() translate: AlfrescoTranslationService) {
console.log('UploadComponent constructor', el);
let site = this.getSiteId();
@@ -106,9 +106,7 @@ export class UploadButtonComponent {
}
});
if (translate) {
this.translationInit(translate);
}
translate.translationInit('node_modules/ng2-alfresco-upload');
}
/**
@@ -131,21 +129,6 @@ export class UploadButtonComponent {
}
}
/**
* Initial configuration for Multi language
* @param translate
*/
translationInit(translate: TranslateService) {
this.translate = translate;
let userLang = navigator.language.split('-')[0]; // use navigator lang if available
userLang = /(fr|en)/gi.test(userLang) ? userLang : 'en';
this.translate.setDefaultLang(userLang);
this.translate.currentLoader.addComponentList('node_modules/ng2-alfresco-upload');
this.translate.getTranslation(userLang);
this.translate.use(userLang);
}
/**
* Show undo notification bar.
*