From 3e54eaf5fe12ec06c99b15088b2b142d7acd8f0c Mon Sep 17 00:00:00 2001 From: Mario Romano Date: Thu, 19 May 2016 19:39:13 +0100 Subject: [PATCH] fix translate --- demo-shell-ng2/app/app.component.ts | 24 +++-------- .../datatable/datatable-demo.component.ts | 27 ++++++------ .../app/components/files/files.component.ts | 4 +- .../app/components/router/AuthRouterOutlet.ts | 10 ++--- demo-shell-ng2/app/main.ts | 8 +--- demo-shell-ng2/package.json | 1 - demo-shell-ng2/systemjs.config.js | 6 +-- ng2-components/ng2-alfresco-core/.npmignore | 14 +++++++ ng2-components/ng2-alfresco-core/package.json | 2 +- ng2-components/ng2-alfresco-core/services.ts | 21 +++++++--- .../services/AlfrescoPipeTranslate.service.ts | 32 +++++++++++++++ ....ts => AlfrescoSettingsService.service.ts} | 0 ...s => AlfrescoTranslationLoader.service.ts} | 8 ++-- .../AlfrescoTranslationService.service.ts | 41 +++++++++++++++++++ ng2-components/ng2-alfresco-login/.npmignore | 14 +++++++ .../ng2-alfresco-login/demo/src/my-app.ts | 11 ++--- .../ng2-alfresco-login/package.json | 10 ++--- .../components/alfresco-login.component.ts | 9 ++-- .../ng2-alfresco-upload/package.json | 3 +- .../file-uploading-dialog.component.ts | 4 +- .../file-uploading-list.component.ts | 4 +- .../src/components/upload-button.component.ts | 27 +++--------- 22 files changed, 172 insertions(+), 108 deletions(-) create mode 100644 ng2-components/ng2-alfresco-core/.npmignore create mode 100644 ng2-components/ng2-alfresco-core/services/AlfrescoPipeTranslate.service.ts rename ng2-components/ng2-alfresco-core/services/{AlfrescoSettingsService.ts => AlfrescoSettingsService.service.ts} (100%) rename ng2-components/ng2-alfresco-core/services/{AlfrescoTranslationService.ts => AlfrescoTranslationLoader.service.ts} (94%) create mode 100644 ng2-components/ng2-alfresco-core/services/AlfrescoTranslationService.service.ts create mode 100644 ng2-components/ng2-alfresco-login/.npmignore diff --git a/demo-shell-ng2/app/app.component.ts b/demo-shell-ng2/app/app.component.ts index 4958ef2f0e..ff256315ad 100644 --- a/demo-shell-ng2/app/app.component.ts +++ b/demo-shell-ng2/app/app.component.ts @@ -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(); diff --git a/demo-shell-ng2/app/components/datatable/datatable-demo.component.ts b/demo-shell-ng2/app/components/datatable/datatable-demo.component.ts index 738ca1a8d1..a23adbd166 100644 --- a/demo-shell-ng2/app/components/datatable/datatable-demo.component.ts +++ b/demo-shell-ng2/app/components/datatable/datatable-demo.component.ts @@ -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,19 +44,19 @@ 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} ] ); - + this.data.setSorting(new DataSorting('name', 'asc')); } } diff --git a/demo-shell-ng2/app/components/files/files.component.ts b/demo-shell-ng2/app/components/files/files.component.ts index a7755ebbe9..83e7f01ccb 100644 --- a/demo-shell-ng2/app/components/files/files.component.ts +++ b/demo-shell-ng2/app/components/files/files.component.ts @@ -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; diff --git a/demo-shell-ng2/app/components/router/AuthRouterOutlet.ts b/demo-shell-ng2/app/components/router/AuthRouterOutlet.ts index d69aabcf35..d68e939d22 100644 --- a/demo-shell-ng2/app/components/router/AuthRouterOutlet.ts +++ b/demo-shell-ng2/app/components/router/AuthRouterOutlet.ts @@ -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; private router: Router; - constructor( - _elementRef: ElementRef, _loader: DynamicComponentLoader, - _parentRouter: Router, @Attribute('name') nameAttr: string, - private authentication: AlfrescoAuthenticationService - ) { + constructor(_elementRef: ElementRef, _loader: DynamicComponentLoader, + _parentRouter: Router, @Attribute('name') nameAttr: string, + private authentication: AlfrescoAuthenticationService) { super(_elementRef, _loader, _parentRouter, nameAttr); this.router = _parentRouter; diff --git a/demo-shell-ng2/app/main.ts b/demo-shell-ng2/app/main.ts index 86f990cc07..ffdfab18f7 100644 --- a/demo-shell-ng2/app/main.ts +++ b/demo-shell-ng2/app/main.ts @@ -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 ]); diff --git a/demo-shell-ng2/package.json b/demo-shell-ng2/package.json index 683cbecd32..e40929ead2 100644 --- a/demo-shell-ng2/package.json +++ b/demo-shell-ng2/package.json @@ -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", diff --git a/demo-shell-ng2/systemjs.config.js b/demo-shell-ng2/systemjs.config.js index 07b0ad4e11..a975ea90ae 100644 --- a/demo-shell-ng2/systemjs.config.js +++ b/demo-shell-ng2/systemjs.config.js @@ -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'}, diff --git a/ng2-components/ng2-alfresco-core/.npmignore b/ng2-components/ng2-alfresco-core/.npmignore new file mode 100644 index 0000000000..da0fb078c2 --- /dev/null +++ b/ng2-components/ng2-alfresco-core/.npmignore @@ -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 diff --git a/ng2-components/ng2-alfresco-core/package.json b/ng2-components/ng2-alfresco-core/package.json index 644158abc7..17a8e58543 100644 --- a/ng2-components/ng2-alfresco-core/package.json +++ b/ng2-components/ng2-alfresco-core/package.json @@ -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", diff --git a/ng2-components/ng2-alfresco-core/services.ts b/ng2-components/ng2-alfresco-core/services.ts index 1383f85f12..ebe5f9d346 100644 --- a/ng2-components/ng2-alfresco-core/services.ts +++ b/ng2-components/ng2-alfresco-core/services.ts @@ -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 ]; diff --git a/ng2-components/ng2-alfresco-core/services/AlfrescoPipeTranslate.service.ts b/ng2-components/ng2-alfresco-core/services/AlfrescoPipeTranslate.service.ts new file mode 100644 index 0000000000..bc6b17f1f0 --- /dev/null +++ b/ng2-components/ng2-alfresco-core/services/AlfrescoPipeTranslate.service.ts @@ -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); + } +} diff --git a/ng2-components/ng2-alfresco-core/services/AlfrescoSettingsService.ts b/ng2-components/ng2-alfresco-core/services/AlfrescoSettingsService.service.ts similarity index 100% rename from ng2-components/ng2-alfresco-core/services/AlfrescoSettingsService.ts rename to ng2-components/ng2-alfresco-core/services/AlfrescoSettingsService.service.ts diff --git a/ng2-components/ng2-alfresco-core/services/AlfrescoTranslationService.ts b/ng2-components/ng2-alfresco-core/services/AlfrescoTranslationLoader.service.ts similarity index 94% rename from ng2-components/ng2-alfresco-core/services/AlfrescoTranslationService.ts rename to ng2-components/ng2-alfresco-core/services/AlfrescoTranslationLoader.service.ts index f310f2ce44..8d0ff62821 100644 --- a/ng2-components/ng2-alfresco-core/services/AlfrescoTranslationService.ts +++ b/ng2-components/ng2-alfresco-core/services/AlfrescoTranslationLoader.service.ts @@ -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(); }); diff --git a/ng2-components/ng2-alfresco-core/services/AlfrescoTranslationService.service.ts b/ng2-components/ng2-alfresco-core/services/AlfrescoTranslationService.service.ts new file mode 100644 index 0000000000..5dba5e562d --- /dev/null +++ b/ng2-components/ng2-alfresco-core/services/AlfrescoTranslationService.service.ts @@ -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); + } +} diff --git a/ng2-components/ng2-alfresco-login/.npmignore b/ng2-components/ng2-alfresco-login/.npmignore new file mode 100644 index 0000000000..da0fb078c2 --- /dev/null +++ b/ng2-components/ng2-alfresco-login/.npmignore @@ -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 diff --git a/ng2-components/ng2-alfresco-login/demo/src/my-app.ts b/ng2-components/ng2-alfresco-login/demo/src/my-app.ts index 058bdcb66f..b4b1ea707a 100644 --- a/ng2-components/ng2-alfresco-login/demo/src/my-app.ts +++ b/ng2-components/ng2-alfresco-login/demo/src/my-app.ts @@ -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 diff --git a/ng2-components/ng2-alfresco-login/package.json b/ng2-components/ng2-alfresco-login/package.json index 80d2a4db49..4fca7de521 100644 --- a/ng2-components/ng2-alfresco-login/package.json +++ b/ng2-components/ng2-alfresco-login/package.json @@ -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" diff --git a/ng2-components/ng2-alfresco-login/src/components/alfresco-login.component.ts b/ng2-components/ng2-alfresco-login/src/components/alfresco-login.component.ts index 5438242980..05d296fa96 100644 --- a/ng2-components/ng2-alfresco-login/src/components/alfresco-login.component.ts +++ b/ng2-components/ng2-alfresco-login/src/components/alfresco-login.component.ts @@ -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); diff --git a/ng2-components/ng2-alfresco-upload/package.json b/ng2-components/ng2-alfresco-upload/package.json index 53b3c90ae7..b6814deb95 100644 --- a/ng2-components/ng2-alfresco-upload/package.json +++ b/ng2-components/ng2-alfresco-upload/package.json @@ -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", diff --git a/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.ts b/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.ts index fa843adb89..e621f0d3f4 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.ts @@ -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 { diff --git a/ng2-components/ng2-alfresco-upload/src/components/file-uploading-list.component.ts b/ng2-components/ng2-alfresco-upload/src/components/file-uploading-list.component.ts index 2c32cc965b..70f6e87fd7 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/file-uploading-list.component.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/file-uploading-list.component.ts @@ -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 { diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts index eba04c0226..2b78646d27 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts @@ -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. *