-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(i18n): angular i18n native implementation #1442
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
Changes from 9 commits
f043eb5
af771a5
489cd81
747c484
a873aeb
40f6f91
8822788
4023323
cd4df83
9b1a020
5b2e29d
745ee4a
0e54cc9
37ac59d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { TRANSLATIONS, TRANSLATIONS_FORMAT, LOCALE_ID } from '@angular/core'; | ||
|
||
export class TranslationProviders { | ||
|
||
public getTranslationFile = (): Promise<any> => { | ||
let noProviders: Object[] = []; | ||
let locale: string = localStorage.getItem('lang') || 'en-US'; | ||
let file: string = `../assets/locale/messages.${locale}.xlf`; | ||
|
||
if(!locale || locale === 'en-US') return Promise.resolve(noProviders); | ||
|
||
return new Promise(function (resolve, reject) { | ||
let xhr = new XMLHttpRequest; | ||
xhr.open('GET', file); | ||
xhr.onload = (data: any) => resolve( | ||
[ | ||
{ provide: TRANSLATIONS, useValue: data.target.response }, | ||
{ provide: TRANSLATIONS_FORMAT, useValue: 'xlf' }, | ||
{ provide: LOCALE_ID, useValue: locale } | ||
] | ||
); | ||
xhr.onerror = () => reject(noProviders); | ||
xhr.send(); | ||
}); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<nav> | ||
<a [routerLink]="['/']" [routerLinkActive]="['router-link-active']" [routerLinkActiveOptions]="{exact:true}">HOME</a> | ||
<a [routerLink]="['/about']" [routerLinkActive]="['router-link-active']" [routerLinkActiveOptions]="{exact:true}">ABOUT</a> | ||
<a [routerLink]="['/']" [routerLinkActive]="['router-link-active']" [routerLinkActiveOptions]="{exact:true}" i18n>HOME</a> | ||
<a [routerLink]="['/about']" [routerLinkActive]="['router-link-active']" [routerLinkActiveOptions]="{exact:true}" i18n>ABOUT</a> | ||
<a (click)="selectLanguage('fr')" *ngIf="lang !== 'fr'">FRANCAIS</a> | ||
<a (click)="selectLanguage('en-US')" *ngIf="lang !== 'en-US'">ENGLISH</a> | ||
</nav> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
declare var System: SystemJSLoader.System; | ||
|
||
System.config(JSON.parse('<%= SYSTEM_CONFIG_DEV %>')); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"> | ||
<file source-language="en" datatype="plaintext" original="ng2.template"> | ||
<body> | ||
<trans-unit id="dcf8f15418a05a2f5b06cfe12eecbb46e94b13e1" datatype="html"> | ||
<source>HOME</source> | ||
<target>ACCUEIL</target> | ||
</trans-unit> | ||
<trans-unit id="2ccc315673e88d7490220d465da566e3acff72d5" datatype="html"> | ||
<source>ABOUT</source> | ||
<target>A PROPOS</target> | ||
</trans-unit> | ||
<trans-unit id="856523466ce29da19581906db092f9bcbe939362" datatype="html"> | ||
<source>Angular 2 Seed is a starter project that implements best practices in coding, building and testing Angular 2 apps.</source> | ||
<target>Angular 2 Seed est un kit de démarrage qui implémente les bonnes pratiques, la compilation et le testing des application Angular 2.</target> | ||
</trans-unit> | ||
<trans-unit id="6cdb1fea93d77c07950c0c76c6e0ad79ebbef084" datatype="html"> | ||
<source>Features</source> | ||
<target>Inclus</target> | ||
</trans-unit> | ||
<trans-unit id="fb798124b25a52ab081695795ca745abb52f8e95" datatype="html"> | ||
<source>Howdy! Here's a list of awesome computer scientists. Do you know any others? Add to the list yourself.</source> | ||
<target>Hello! Voici une liste d'informaticiens connus. Tu en connais d'autres? ajoute-les à la liste.</target> | ||
</trans-unit> | ||
<trans-unit id="f6755cff4957d5c3c89bafce5651f1b6fa2b1fd9" datatype="html"> | ||
<source>Add</source> | ||
<target>Ajouter</target> | ||
</trans-unit> | ||
</body> | ||
</file> | ||
</xliff> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
declare module 'del' { | ||
var del: IDel; | ||
export = del; | ||
interface IDel { | ||
sync: { | ||
(patterns: any): void; | ||
}; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import '../../../src/client/app/main'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ruffiem this file doesn't seem used anywhere, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mgechev it's used by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got it. Can you pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no -p option with ng-xi18n yet but it's being discussed on the angular repo (2201). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I added this as last step in order to not pollute the seed's tasks directory. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as del from 'del'; | ||
import { join } from 'path'; | ||
|
||
import Config from '../../config'; | ||
|
||
/** | ||
* Removes all the js, js.map and metadata.json from the src and tools directories | ||
*/ | ||
export = () => { | ||
let source = [ | ||
'gulpfile.js', | ||
'gulpfile.js.map', | ||
join(Config.TOOLS_DIR, '**/*.js'), | ||
join(Config.TOOLS_DIR, '**/*.js.map'), | ||
join(Config.TOOLS_DIR, '**/*.metadata.json'), | ||
join(Config.APP_SRC, '**/*.js'), | ||
join(Config.APP_SRC, '**/*.js.map'), | ||
join(Config.APP_SRC, '**/*.metadata.json') | ||
]; | ||
|
||
return del.sync(source); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could use the Angular2 HTTP provider here instead of XMLHttpRequest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried but it was resolving to
undefined
maybe I was missing something...Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Bigous this service is invoked before bootstrap so I'm not sure if it is possible since the Angular's i18n functionality is part of the compilation process (in this case JiT).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mgechev True. It should be a service where the Application module depends so... or keep it as it is :)