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

@@ -18,13 +18,11 @@
import { Component } from 'angular2/core';
import { ControlGroup, FormBuilder, Validators } from 'angular2/common';
import { Router, RouteConfig, ROUTER_DIRECTIVES } from 'angular2/router';
import { AlfrescoAuthenticationService } from 'ng2-alfresco-login/ng2-alfresco-login';
import { MDL } from 'ng2-alfresco-core/material';
import { FilesComponent } from './components/files/files.component';
import { AlfrescoLoginComponent } from 'ng2-alfresco-login/ng2-alfresco-login';
import { AlfrescoLoginComponent, AlfrescoAuthenticationService } from 'ng2-alfresco-login/ng2-alfresco-login';
import { AuthRouterOutlet } from './components/router/AuthRouterOutlet';
import { AlfrescoSettingsService } from 'ng2-alfresco-core/services';
import { TranslateService, TranslatePipe } from 'ng2-translate/ng2-translate';
import { AlfrescoSettingsService, AlfrescoTranslationService, AlfrescoPipeTranslate } from 'ng2-alfresco-core/services';
import { UploadButtonComponent } from 'ng2-alfresco-upload/ng2-alfresco-upload';
import { DataTableDemoComponent } from './components/datatable/datatable-demo.component';
import { AlfrescoSearchComponent } from 'ng2-alfresco-search/ng2-alfresco-search';
@@ -35,7 +33,7 @@ declare var document: any;
selector: 'my-app',
templateUrl: 'app/app.component.html',
directives: [ROUTER_DIRECTIVES, AuthRouterOutlet, MDL],
pipes: [TranslatePipe]
pipes: [AlfrescoPipeTranslate]
})
@RouteConfig([
{path: '/home', name: 'Home', component: FilesComponent},
@@ -52,7 +50,7 @@ export class AppComponent {
constructor(private _fb: FormBuilder,
public auth: AlfrescoAuthenticationService,
public router: Router,
translate: TranslateService,
translate: AlfrescoTranslationService,
alfrescoSettingsService: AlfrescoSettingsService) {
alfrescoSettingsService.host = 'http://192.168.99.100:8080';
@@ -60,7 +58,7 @@ export class AppComponent {
searchTerm: ['', Validators.compose([Validators.required, Validators.minLength(3)])]
});
this.translationInit(translate);
translate.translationInit('');
}
isActive(instruction: any[]): boolean {
@@ -83,18 +81,6 @@ export class AppComponent {
this.translate.use(lang);
}
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('en');
this.translate.currentLoader.addComponentList('');
this.translate.getTranslation(userLang);
this.translate.use(userLang);
}
hideDrawer() {
// todo: workaround for drawer closing
document.querySelector('.mdl-layout').MaterialLayout.toggleDrawer();

View File

@@ -15,22 +15,21 @@
* limitations under the License.
*/
import {Component} from 'angular2/core';
import {TranslatePipe} from 'ng2-translate/ng2-translate';
import { Component } from 'angular2/core';
import { AlfrescoPipeTranslate } from 'ng2-alfresco-core/services';
import {
ALFRESCO_DATATABLE_DIRECTIVES,
ObjectDataTableAdapter, DataSorting
} from 'ng2-alfresco-datatable/ng2-alfresco-datatable';
declare let __moduleName:string;
declare let __moduleName: string;
@Component({
moduleId: __moduleName,
selector: 'datatable-demo',
templateUrl: './datatable-demo.component.html',
directives: [ALFRESCO_DATATABLE_DIRECTIVES],
pipes: [TranslatePipe]
pipes: [AlfrescoPipeTranslate]
})
export class DataTableDemoComponent {
data: ObjectDataTableAdapter;
@@ -45,16 +44,16 @@ export class DataTableDemoComponent {
this.data = new ObjectDataTableAdapter(
[
{ id: 1, name: 'Name 1', createdBy: createdBy, icon: 'material-icons://folder_open' },
{ id: 2, name: 'Name 2', createdBy: createdBy, icon: 'material-icons://accessibility' },
{ id: 3, name: 'Name 3', createdBy: createdBy, icon: 'material-icons://alarm' },
{ id: 4, name: 'Image 1', createdBy: createdBy, icon: imageUrl }
{id: 1, name: 'Name 1', createdBy: createdBy, icon: 'material-icons://folder_open'},
{id: 2, name: 'Name 2', createdBy: createdBy, icon: 'material-icons://accessibility'},
{id: 3, name: 'Name 3', createdBy: createdBy, icon: 'material-icons://alarm'},
{id: 4, name: 'Image 1', createdBy: createdBy, icon: imageUrl}
],
[
{ type: 'image', key: 'icon', title: '', srTitle: 'Thumbnail' },
{ type: 'text', key: 'id', title: 'Id', sortable: true},
{ type: 'text', key: 'name', title: 'Name', cssClass: 'full-width name-column', sortable: true },
{ type: 'text', key: 'createdBy.name', title: 'Created By', sortable: true }
{type: 'image', key: 'icon', title: '', srTitle: 'Thumbnail'},
{type: 'text', key: 'id', title: 'Id', sortable: true},
{type: 'text', key: 'name', title: 'Name', cssClass: 'full-width name-column', sortable: true},
{type: 'text', key: 'createdBy.name', title: 'Created By', sortable: true}
]
);

View File

@@ -23,7 +23,7 @@ import {
} from 'ng2-alfresco-documentlist/ng2-alfresco-documentlist';
import { MDL } from 'ng2-alfresco-core/material';
import { ALFRESCO_ULPOAD_COMPONENT } from 'ng2-alfresco-upload/ng2-alfresco-upload';
import { TranslatePipe } from 'ng2-translate/ng2-translate';
import { AlfrescoPipeTranslate } from 'ng2-alfresco-core/services';
declare let __moduleName: string;
@@ -33,7 +33,7 @@ declare let __moduleName: string;
templateUrl: './files.component.html',
directives: [DOCUMENT_LIST_DIRECTIVES, MDL, ALFRESCO_ULPOAD_COMPONENT],
providers: [DOCUMENT_LIST_PROVIDERS],
pipes: [TranslatePipe]
pipes: [AlfrescoPipeTranslate]
})
export class FilesComponent {
breadcrumb: boolean = false;

View File

@@ -16,7 +16,7 @@
*/
import { ElementRef, DynamicComponentLoader, Directive, Attribute } from 'angular2/core';
import { Router, RouterOutlet, ComponentInstruction } from 'angular2/router';
import {AlfrescoAuthenticationService} from 'ng2-alfresco-login/ng2-alfresco-login';
import { AlfrescoAuthenticationService } from 'ng2-alfresco-login/ng2-alfresco-login';
@Directive({selector: 'auth-router-outlet'})
export class AuthRouterOutlet extends RouterOutlet {
@@ -24,11 +24,9 @@ export class AuthRouterOutlet extends RouterOutlet {
publicRoutes: Array<string>;
private router: Router;
constructor(
_elementRef: ElementRef, _loader: DynamicComponentLoader,
constructor(_elementRef: ElementRef, _loader: DynamicComponentLoader,
_parentRouter: Router, @Attribute('name') nameAttr: string,
private authentication: AlfrescoAuthenticationService
) {
private authentication: AlfrescoAuthenticationService) {
super(_elementRef, _loader, _parentRouter, nameAttr);
this.router = _parentRouter;

View File

@@ -19,17 +19,13 @@ import { bootstrap } from 'angular2/platform/browser';
import { AppComponent } from './app.component';
import { ROUTER_PROVIDERS } from 'angular2/router';
import { HTTP_PROVIDERS } from 'angular2/http';
import { TranslateLoader, TranslateService } from 'ng2-translate/ng2-translate';
import { ALFRESCO_AUTHENTICATION } from 'ng2-alfresco-login/ng2-alfresco-login';
import { ALFRESCO_CORE_PROVIDERS } from 'ng2-alfresco-core/services';
import { AlfrescoTranslationLoader } from 'ng2-alfresco-core/services';
import { provide } from 'angular2/core';
import { ALFRESCO_CORE_PROVIDERS, AlfrescoTranslationService } from 'ng2-alfresco-core/services';
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
HTTP_PROVIDERS,
provide(TranslateLoader, {useClass: AlfrescoTranslationLoader}),
TranslateService,
AlfrescoTranslationService,
ALFRESCO_AUTHENTICATION,
ALFRESCO_CORE_PROVIDERS
]);

View File

@@ -53,7 +53,6 @@
"ng2-alfresco-login": "^0.1.0",
"ng2-alfresco-search": "^0.1.1",
"ng2-alfresco-upload": "^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

@@ -19,11 +19,10 @@
// map tells the System loader where to look for things
var map = {
'ng2-uploader': 'node_modules/ng2-uploader',
'ng2-alfresco-core': 'node_modules/ng2-alfresco-core',
'ng2-alfresco-core': 'node_modules/ng2-alfresco-core/dist',
'ng2-alfresco-datatable': 'node_modules/ng2-alfresco-datatable/dist',
'ng2-alfresco-documentlist': 'node_modules/ng2-alfresco-documentlist/dist',
'ng2-alfresco-login': 'node_modules/ng2-alfresco-login',
'ng2-alfresco-login': 'node_modules/ng2-alfresco-login/dist',
'ng2-alfresco-search': 'node_modules/ng2-alfresco-search/dist',
'ng2-alfresco-upload': 'node_modules/ng2-alfresco-upload/dist',
'ng2-translate': 'node_modules/ng2-translate',
@@ -36,7 +35,6 @@
format: 'register',
defaultExtension: 'js'
},
'ng2-uploader': {defaultExtension: 'js'},
'ng2-alfresco-core': {defaultExtension: 'js'},
'ng2-alfresco-datatable': {defaultExtension: 'js'},
'ng2-alfresco-documentlist': {defaultExtension: 'js'},

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.
*