Repository navigation
[Discussion] angular-cli and i18n (ng-xi18n + ngc) #2201
Copy link
Copy link
Closed
Labels
Description
With angular's i18n working quite good now, I wanted to start a general discussion about how the angular-cli will be supposed to work with it.
According to this statement on StackOverflow from @Brocco, angular-cli will eventually make use of AOT compilation. This means, that ngc will be used, which in turn will respect xlf files for translations. For JIT builds (development builds), we could make use of a raw webpack loader, which loads a xlf file as string and provides this as translation.
Here are some questions which come to my mind and I think need to be considered in future development:
- Currently, for a production build, everything (vendor's code + application code) is bundled into one single
bundle.jsfile. With multiple translations, will we be supposed to have one complete bundle for each language? This seems to be a very inpractical approach. Bundling every translation into thebundle.jsis not practical either, as in maybe 99% of all cases, one language is sufficient. Imagine a popular app, built with angular, which is used from people all over the world. We 1) don't want to ship abundle.jscontaining all possible translations, because eventually they will blow up the bundle size. We 2) don't want to have hundrets of bundles, each for one language. Maybe it would be good to split thebundle.jsinto two separate bundles: 1) vendors library code, 2) NgFactory code. For each language, a dedicatedngfactory-bundle.lang-LANG.jswould then be created. - What about libraries that support localization? For example a library which supplies some input components (like a calendar) which needs to be localized.
- How can we reliably detect the language and load the app accordingly? At the moment, this has to occur during bootstrap, but what about detecting the browser locale or maybe the users preference (this means: much later than bootstrap time; after a database request, fetching the user settings after auth)?
- As
ngis a façade: would we need anng i18ncommand to hide the possibly rather complexng-xi18ncall (regarding hiding passed parameters... a call could otherwise look like this:./node_modules/.bin/ng-xi18n -p src/tsconfig.json ......)? Or could this be automated with some kind of watch (I don't think so, asng-xi18ntakes some time to complete, even with a small app)? - Where would we store the localization files? Maybe
src/i18n/would be a good place for the start. If we would like to encourage a set of localization files for each module, it should be located atsrc/<module-name>/i18n/or maybesrc/i18n/<module-name>/. The latter approach would be better for translator-teams, or translation-tools I think
Reactions are currently unavailable
Activity
elvirdolic commentedon Oct 6, 2016
As we have now AOT in angular-cli the question is how we can use i18n with aot and CLI? At the moment I don't see the possibility.
@christiandreher already said this is a common case for apps to support multiple languages and I think it would be a great experience to have this in CLI to make the experience complete or at least some instructions how that can be achieved outside of CLI magic blackbox.
filipesilva commentedon Oct 9, 2016
This is something we'd like to have, but there's still a fair bit of architecture discussion around it that we need to do before getting to it.
mbeckenbach commentedon Oct 22, 2016
@elvirdolic That would be great for the moment.
kemsky commentedon Oct 24, 2016
Is it possible to use i18n with angular-cli now?
jfmaeck commentedon Oct 25, 2016
@rolandoldengarm are you using i18n + Angular CLI + Ahead of Time Compilation? If so, I would very much appreciate any hints on how to get this working.
For people struggling with i18n + Angular CLI: It took me a while to figure out the correct way to call ng-xi18n (although it is mentioned in this issue's description, actually):
Or in package.json:
kemsky commentedon Oct 25, 2016
@jfmaeck, thanks for
tsconfig.jsontip.@rolandoldengarm, it works in JIT mode, but in AOT
bootstrapModuleis replaced bybootstrapModuleFactoryautomatically, i see i18n providers are passed but localization does not work.serhiisol commentedon Nov 7, 2016
@jfmaeck With this option i got this message
jfmaeck commentedon Nov 8, 2016
@serhiisol I am not sure but perhaps there is something wrong with your tsconfig.json file? The
includesection should be a sibling ofcompilerOptions. Perhaps it is a descendant in your tsconfig.json? If not, unfortunately I have no other idea.cladera commentedon Nov 8, 2016
I opened this issue angular/angular#12749 yesterday. @vicb asked to open an issue in CLI's project but I came across this discussion. Is it related or should I open a new issue anyway?
serhiisol commentedon Nov 8, 2016
@jfmaeck yes, you're right, but previously include was a descendant.
@cladera I don't think you should, as @filipesilva mentioned, they have a lot of things to discuss/design first, before adding it to CLI, imo.
cladera commentedon Nov 8, 2016
@serhiisol ok!
For those dealing with the same issue, @kemsky's workaround works. When importing a sass partial use the full file name.
Example:
Instead of
77 remaining items
feloy commentedon Feb 14, 2017
@rolandoldengarm It seems that this LOCALE_ID is set only with AOT compilation. You can user ng serve --aot.
ruffiem commentedon Feb 18, 2017
@Dimitry-k ng-translate is a tool made by developers for developers. Not translators. Arch is JSON, there is no context, we can deal with plural, gender on the template logic but when it comes to hire a professional to translate your file, you can be very disappointed.
XLIFF is an international standard. I don't think it's a matter of technology, it's a matter of using the right tool for the right purpose.
itsnotvalid commentedon Feb 20, 2017
The original approach started from this thread is still something better than having a complete bundle for each language supported using this method. I think the discussion should go back to that direction.
ruffiem commentedon Feb 20, 2017
I'm still wondering why language files are part of the compilation... It's not because of the CLI though.
cherryland commentedon Feb 21, 2017
I agree with @itsnotvalid. Compiling complete bundles for each language is bs. Point. End of story.
I suggest you take a look at Mozilla's L20n localization framework (MDN: Introducing L20n). The framework basically observes DOM trees using the MutationObserver API, and also uses an "industry standard" translation source file format
locale.ja.ftl
the configuration goes into your html
where
{locale}will be replaced bynavigator.languageautomatically.CanKattwinkel commentedon Feb 22, 2017
@0xcherry How about the performance on this approach?
In general this does not only affect language files and strings in the template but also date, decimal and currency. Is Angular capable to change this dynamically while runtime? Afaik AngularJS was not.
figuerres commentedon Mar 10, 2017
my comment: the messages / text in the app should be a thing that can be stored in some kind of data file and loaded at run time.
There are some cases where an app might benefit from multiple versions but for a lot of cases it's better to have one set of code and markup that you maintain.
for all of the "western" langues (english, french, german,spanish, etc...) the layout of the app does not need to be altered, just the text of the messages and the logic for decimal, comma and dates.
for some other langaues a really good treatment might need more, i am thinking of asian and middle eastern where the rules for flow are very different right to left or down not across.
ishitatsuyuki commentedon Mar 17, 2017
I think the seamless bootstrap is high priority and we should find a solution ASAP.
My proposal: do something similar to router's lazyroutes. We should auto-generate the router for the root (put the AppModule into language subfolder), and lazy load all compiled AppModule. This way, we can seamlessly switch them.
The way to configure it (like, default redirection) remains for discussion.
filipesilva commentedon May 22, 2017
With
ng xi18n(https://github.com/angular/angular-cli/wiki/xi18n) and the the--i18n-file/--i18n-formatflags forng build/serve(https://github.com/angular/angular-cli/wiki/build) I think the actionable parts of this issue are addressed.Runtime loading of different languages is not a feature that currently exists for Angular's
i18nthough. If you want to request it, you should do so at https://github.com/angular/angular instead of here.KTKate commentedon Jun 28, 2017
Combined with #1253 this is an irksome bug. We have to manually import colors/fonts/etc in every scss file across the app but we have to use non-standard syntax to do it if we want i18n to work.
shobhit12345 commentedon Jul 12, 2018
Is there any way to create seperate xlf file for each module?
angular-automatic-lock-bot commentedon Jun 3, 2021
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.