-
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
Conversation
@ruffiem I took only a brief look at your changes but it looks great so far! Thanks for the PR, I'll merge the it tonight or tomorrow morning. |
Thanks! Just saw there's something wrong with the production build, it completes but breaks at runtime on "System.import is not a function" in |
Working on the issue, hope to fix it by the end of the day. Does systemjs text plugin may cause such error ? |
Yes, in production we are excluding SystemJS from the bundle. I'd recommend you to use the Angular's http service instead. Otherwise it looks good to me! |
Great, thanks. I didn't know System.import was just an xhr :) I will refactor a little, run a few tests and push when everything seems correct. |
@ruffiem another small thing - we also support AoT compilation so you'd have to update |
Ok now it does work on both dev and prod but we have a bigger challenge : when scanning the code for i18n attributes, angular gives a specific id based on the textnode format (white spaces, returns, breaking spaces...). Thing is, with minification/uglification we lose the format, the id is changing and the translation is lost. Can't think of anything "easy" to fix it right now. EDIT: Or maybe we can minify the XLF as well to have the same formatting ? |
The id is changed by uglify performing mangling? If so, we can disable mangling for build.prod and leave it only for build.prod.exp where we may not have such problem because of the AoT. |
Exactly. Also, mangling the XLF is not possible since ids are hardcoded in the file. I created an issue on the angular repo as they should rely on content instead of formatting IMO. |
I have updated the text content to avoid translation to break from the seed on prod, ids won't change but the text has to be written inline. <h1 i18n>Howdy!</h1> not <h1 i18n>
Howdy
!
</h1> Also, TP from |
@ruffiem you can also disable mangling, which should be fine. |
I have tried to disable mangling but the result was the same (except that the ids were changing but still not matching the ones from the XLF). Did you try too ? |
@ruffiem I'll give it a try later today. I'm releasing beta.1 of codelyzer today with bug fixes. |
I took a final look. It looks great, thanks for the effort one more time. My suggestion will be to keep it disabled by default because a lot of people will be confused by the bootstrap process. Lets keep /**
* Bootstraps the application and makes the ROUTER_PROVIDERS and the APP_BASE_HREF available to it.
* @see https://angular.io/docs/ts/latest/api/platform-browser-dynamic/index/bootstrap-function.html
*/
import { enableProdMode } from '@angular/core';
// The browser platform with a compiler
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
// Load i18n providers
// import { TranslationProviders } from './i18n.providers';
// The app module
import { AppModule } from './app.module';
if (String('<%= ENV %>') === 'prod') { enableProdMode(); }
// Compile and launch the module with i18n providers
// let TP = new TranslationProviders();
// TP.getTranslationFile().then((providers: any) => {
// const options: any = { providers };
platformBrowserDynamic().bootstrapModule(AppModule/*, options*/);
// }); I've also removed the comments for the Service Workers that I added in the past because they are out of date. We can add a wiki article of how the i18n can be enabled (basically uncomment the Finally commenting in the language switching logic. Currently directly accessing What do you think about this? |
Sounds great, I will make a wiki page about how to use i18n if you allow me to. And thanks to you for the seed, do not hesitate to tell me if you need help or something 👍 |
Sounds good! Looking for the updates in the PR and the wiki page, then I'll be ready to merge. |
Ok, should be fine now, I've also updated the package.json to match current master. |
Since i18n is an option, maybe we should create a few options in |
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.
Great Job @ruffiem . Just a minor change and a wish :D
); | ||
xhr.onerror = () => reject(noProviders); | ||
xhr.send(); | ||
}); |
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...
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 :)
<p> | ||
Howdy! Here's a list of awesome computer scientists. Do you know any others? Add to the list yourself. | ||
</p> | ||
<p>Howdy! Here's a list of awesome computer scientists. Do you know any others? Add to the list yourself.</p> |
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
@@ -0,0 +1 @@ | |||
import '../../../src/client/app/main'; |
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.
@ruffiem this file doesn't seem used anywhere, right?
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 it's used by ng-xi18n
as an entry point to the application. Since ng-xi18n
relies on the tsconfig.json
and src
folder it excluded, I needed to find a way in 🙄
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 got it. Can you pass src/client/tsconfig.json
as argument of ng-xi18n
? For instance in ngc it'll be: ngc -p src/client/tsconfig.json
.
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.
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 comment
The 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.
added systemjs-text-plugin to allow systemjs deal with XLIFF filesapp.through.ts
inseed/tasks
foldernpm run i18n
task to extract content and create former messages.xlfsrc/client/assets/locale