Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Adding i18n support to the client. #94

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/angular-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = function(defaults) {
'es6-shim/es6-shim.js',
'reflect-metadata/**/*.+(js|js.map)',
'rxjs/**/*.+(js|js.map)',
'ng2-translate/**/*.*',
'@angular/**/*.+(js|js.map)'
]
});
Expand Down
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@angular/platform-browser-dynamic": "2.0.0-rc.1",
"@angular/router": "2.0.0-rc.1",
"es6-shim": "^0.35.0",
"ng2-translate": "2.1.0",
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6",
"systemjs": "0.19.26",
Expand Down
7 changes: 7 additions & 0 deletions client/src/app/+home/home.component.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@

<div>
{{ 'OPEN_PENSION' | translate }}
</div>
Change language:
<select (change)="translate.use($event.target.value)">
<option *ngFor="let lang of ['he', 'en']" [selected]="lang === translate.currentLang">{{lang}}</option>
</select>
<op-managing-bodies></op-managing-bodies>
4 changes: 3 additions & 1 deletion client/src/app/+home/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component } from '@angular/core';
import { TranslateService, TranslatePipe } from 'ng2-translate/ng2-translate';

import { ManagingBodiesComponent } from '../+managing-bodies/managing-bodies.component';

Expand All @@ -7,11 +8,12 @@ import { ManagingBodiesComponent } from '../+managing-bodies/managing-bodies.com
selector: 'op-home',
templateUrl: 'home.component.html',
styleUrls: ['home.component.css'],
pipes: [TranslatePipe],
directives: [ManagingBodiesComponent]
})

export class HomeComponent {

constructor() {}
constructor(public translate: TranslateService) {}

}
15 changes: 13 additions & 2 deletions client/src/app/op.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component } from '@angular/core';
import { HTTP_PROVIDERS } from '@angular/http';
import { Routes, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from '@angular/router';
import { TranslateService, TRANSLATE_PROVIDERS } from 'ng2-translate/ng2-translate';

import { HomeComponent } from './+home';
import { AboutComponent } from './+about';
Expand All @@ -12,7 +13,7 @@ import { ManagingBodiesComponent } from './+managing-bodies';
templateUrl: 'op.component.html',
styleUrls: ['op.component.css'],
directives: [ROUTER_DIRECTIVES],
providers: [HTTP_PROVIDERS, ROUTER_PROVIDERS]
providers: [HTTP_PROVIDERS, ROUTER_PROVIDERS, TRANSLATE_PROVIDERS]
})

@Routes([
Expand All @@ -32,5 +33,15 @@ import { ManagingBodiesComponent } from './+managing-bodies';
])

export class OpAppComponent {
title = 'op works!';
title: string = 'op works!';

constructor(public translate: TranslateService) {
// use navigator lang if available
Copy link
Member

@nirgn975 nirgn975 Jun 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ordavidil
Implements OnInit.
Import OnInit from '@angular/core', add the implements OnInit interface, and move all this logic to ngOnInit function [Style 09-01]. There shouldn't be any logic in the constructor.

var userLang = navigator.language.split('-')[0];
userLang = /(he|en)/gi.test(userLang) ? userLang : 'he';

console.log(userLang);
// this trigger the use of the hebrew or english language after setting the translations.
translate.use(userLang);
}
}
3 changes: 3 additions & 0 deletions client/src/i18n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"OPEN_PENSION": "Open Pension"
}
3 changes: 3 additions & 0 deletions client/src/i18n/he.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"OPEN_PENSION": "פנסיה פתוחה"
}
4 changes: 4 additions & 0 deletions client/src/system-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
**********************************************************************************************/
/** Map relative paths to URLs. */
const map: any = {
'ng2-translate': 'vendor/ng2-translate'
};

/** User packages configuration. */
const packages: any = {
'ng2-translate': {
defaultExtension: 'js'
}
};

////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down