-
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 all 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,30 @@ | ||
import { TRANSLATIONS, TRANSLATIONS_FORMAT, LOCALE_ID } from '@angular/core'; | ||
|
||
export class TranslationProviders { | ||
|
||
public getTranslationFile = (): Promise<any> => { | ||
let noProviders: Object[] = []; | ||
|
||
// Define a way to retrieve the local information | ||
let locale: string = 'en-US'; | ||
|
||
// Set the directory to the translation files | ||
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(); | ||
}); | ||
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 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 commentThe reason will be displayed to describe this comment to others. Learn more. I tried but it was resolving to 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. @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 commentThe 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 :) |
||
} | ||
}; |
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,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.
Could you add some more examples on use (like how do we can translate numbers and variables and/or plurals)
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.
Yes, totally, but it seems like pluralization is not working well (especially 'other'). plnkr