You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is this Possible with the current approach of angular libraries , can we have i18n support for Libraries so that i can build the lib using locale specific data .
Currently in the Angular Docs both these topics are under different Leaf Nodes and not related . But we feel it's a valid requirement of having Libraries work with i18n
If you are using ng-packagr as builder/packager for your Angular libraries, is here your answer for current version (a.k.a without ivy): ng-packagr/ng-packagr#695
@rmedaer Thanks for the links, So untill and unless Ivy comes to the rescue we have no other options? Also if we plan on usong ng-packager will be it possible to have i18n support for Libs as the link mentioned is still and open issue ? can you please shed some more light on the same .
Also if we plan on usong ng-packager will be it possible to have i18n support for Libs as the link mentioned is still and open issue ?
I guess ng-packagr guys will not work-hard on previous Angular renderer because ivy is planned for Q1/Q2 2019.
About next angular release (8.0.0) I cannot answer this since new i18n on ivy is not yet finished. Again as far as I know (as external observer) @ocombejust started to implement translation loaders. Meaning that "provides translation to/from libraries" will depends on services in top of i18n compilation/configuration...
@rmedaer
w.r.t your questions these are things i am looking at
Would you like to package your library with translations ? Yes
(or) would you like to provide translations from your application ?( Maybe both if possible else No )
Are you compiling in AOT or JIT ? AOT (Lib only complies in AOT if i am not wrong)
Did you listen to ngx-translate ? Even if ivy will deprecate ngx-translate it might be an alternative for now.(Presently we are looking at ngx-translate Is it the only way as of now ..)
For angular components from a separate library it works fine when you have the component tagged with i18n - When running ng xi18n inside your application that consumes the library you get the tags inside the .xlf for these components.
But what about the usage of $localize inside a service for example? When running ng xi18n inside the library itself the translations are created but not when running it inside an application.
Do we need to merge these two translation files or is the extraction of the $localize not supported and we can only have translations in components?
Sorry to dig out such an old issue but I could only find information about localization with applications and not much about libraries.
@wasdJens - could you provide an example of this not working? I thought it should, since the $localize calls would make there way into your final application build, where the i18n extractor would grab them...
When installing the library in the other angular application (Running 10.2.4) and running ng xi18n (Since ng extract-i18n is not yet supported there according to the docs) I get the following response (Missing the $localize)
I can reproduce the same behavior in our real source code (Also running under angular 10.2.4). I am not quite sure if this is a problem with angular itself or the configuration I am using is incorrect. Our solution is most likely to bump to Angular 11 since we are not using any advanced features that are no longer supported or other issues.
This sounds like it is working as expected in v11 and not (as expected) in v10. The Ivy extraction was not available in earlier versions of Angular. So indeed your solution is to update to the latest version.
I am going to close this as it appears that there is no problem with the latest version of Angular.
Maybe you could also verify my understanding of the current Angular library translation process:
Extract messages from the library using: ng extract-i18n test-lib. This results in a messages.xlf file containing only translations from that library 'test-lib'.
Create language specific XLF translation files for the library.
Publish the library to npm (including these XLF translation files)
Consume the library in another app (e.g. 'some-app') as an npm dependency and use 36792 to merge the library translations files into the translation files of 'some-app'.
@michaelhunziker - yes that is correct. I am sorry that the docs are a bit behind on this. And also that extracting messages from libraries is not straightforward.
Activity
rmedaer commentedon Mar 27, 2019
It's (not yet) possible to do i18n in libraries (as far as I know). However, as explained by @ocombe it will be included with ivy.
I recommend the following talk for more details : https://www.youtube.com/watch?v=miG-ghJhFPc
rmedaer commentedon Mar 27, 2019
If you are using ng-packagr as builder/packager for your Angular libraries, is here your answer for current version (a.k.a without ivy): ng-packagr/ng-packagr#695
rahulrsingh09 commentedon Mar 27, 2019
@rmedaer Thanks for the links, So untill and unless Ivy comes to the rescue we have no other options? Also if we plan on usong ng-packager will be it possible to have i18n support for Libs as the link mentioned is still and open issue ? can you please shed some more light on the same .
rmedaer commentedon Mar 27, 2019
Actually to answer I also have few questions:
I guess ng-packagr guys will not work-hard on previous Angular renderer because ivy is planned for Q1/Q2 2019.
About next angular release (8.0.0) I cannot answer this since new i18n on ivy is not yet finished. Again as far as I know (as external observer) @ocombe just started to implement translation loaders. Meaning that "provides translation to/from libraries" will depends on services in top of i18n compilation/configuration...
I guess the best to advice you is @ocombe and actually he already did a lot here.
rahulrsingh09 commentedon Mar 29, 2019
@rmedaer
w.r.t your questions these are things i am looking at
Would you like to package your library with translations ? Yes
(or) would you like to provide translations from your application ?( Maybe both if possible else No )
Are you compiling in AOT or JIT ? AOT (Lib only complies in AOT if i am not wrong)
Did you listen to ngx-translate ? Even if ivy will deprecate ngx-translate it might be an alternative for now.(Presently we are looking at ngx-translate Is it the only way as of now ..)
fjoalland commentedon Jul 31, 2019
Any more news about this issue?
SantiagoIlli commentedon Sep 19, 2019
See this comment
vgb1993 commentedon Jan 29, 2020
I also need my libs to provide their own translations.
JanEggers commentedon Apr 28, 2020
@ocombe any news?
ocombe commentedon May 1, 2020
@petebacondarwin ? ^
petebacondarwin commentedon May 1, 2020
So two PRs that are in flight to help support translations in libraries are:
I am working a full tilt on this stuff, except for the odd ngcc fix.
ozkoidi commentedon May 13, 2020
Any news or estimated release date for this?
21 remaining items
wasdJens commentedon Jan 29, 2021
For angular components from a separate library it works fine when you have the component tagged with
i18n- When runningng xi18ninside your application that consumes the library you get the tags inside the.xlffor these components.But what about the usage of
$localizeinside a service for example? When runningng xi18ninside the library itself the translations are created but not when running it inside an application.Do we need to merge these two translation files or is the extraction of the $localize not supported and we can only have translations in components?
Sorry to dig out such an old issue but I could only find information about localization with applications and not much about libraries.
petebacondarwin commentedon Jan 29, 2021
@wasdJens - could you provide an example of this not working? I thought it should, since the
$localizecalls would make there way into your final application build, where the i18n extractor would grab them...wasdJens commentedon Jan 29, 2021
@petebacondarwin Gonna try to provide a sample library / app configuration since the working project is closed code.
wasdJens commentedon Feb 1, 2021
Hey, sorry for late response from my side.
I have tried to pinpoint my issue to maybe a misconfigured project / library.
I have also created a sample repo with three angular projects inside:
$localizeandi18nWhen running
ng extract-i18nin the v11 app$localizeseems to work and is extracted from the library.When installing the library in the other angular application (Running 10.2.4) and running
ng xi18n(Sinceng extract-i18nis not yet supported there according to the docs) I get the following response (Missing the$localize)I can reproduce the same behavior in our real source code (Also running under angular 10.2.4). I am not quite sure if this is a problem with angular itself or the configuration I am using is incorrect. Our solution is most likely to bump to Angular 11 since we are not using any advanced features that are no longer supported or other issues.
petebacondarwin commentedon Feb 2, 2021
Thanks for looking into this further @wasdJens.
This sounds like it is working as expected in v11 and not (as expected) in v10. The Ivy extraction was not available in earlier versions of Angular. So indeed your solution is to update to the latest version.
I am going to close this as it appears that there is no problem with the latest version of Angular.
michaelhunziker commentedon Feb 7, 2021
@petebacondarwin: I just wanted to try to extract messages from my Angular library (project generated with the latest CLI, 11.1.4):
ng extract-i18n test-lib(the documentation states that the last parameter is the name of the Angular library: https://angular.io/cli/extract-i18n)Unfortunately I get the following error:
Versions:
Repo: https://github.com/michaelhunziker/angular-i18n-library/
What am I doing wrong?
Maybe you could also verify my understanding of the current Angular library translation process:
ng extract-i18n test-lib. This results in a messages.xlf file containing only translations from that library 'test-lib'.destus90 commentedon Feb 8, 2021
@michaelhunziker
perhaps you didn't define
extract-i18nbuilder for that lib? Something like https://github.com/michaelhunziker/angular-i18n-library/blob/main/angular.json#L76-L81michaelhunziker commentedon Feb 8, 2021
@destus90 I just added that target: michaelhunziker/angular-i18n-library@3a4be6e
When running
ng extract-i18n test-libI now get:This seems to be a duplicate of angular/angular-cli#17140 (comment)
Obviously
ng extract-i18nis still not working for libraries and we have to uselocalize-extractaccording to this answerpetebacondarwin commentedon Feb 8, 2021
@michaelhunziker - yes that is correct. I am sorry that the docs are a bit behind on this. And also that extracting messages from libraries is not straightforward.
michaelhunziker commentedon Feb 8, 2021
@petebacondarwin thanks for your confirmation!
It's working now with
localize-extract: https://github.com/michaelhunziker/angular-i18n-library/blob/main/README.mdI also had to add
import '@angular/localize/init';to public-api.ts in order to use $localize within the library: https://github.com/michaelhunziker/angular-i18n-library/blob/main/projects/test-lib/src/public-api.ts#L4as documented here: #36757 (comment)
petebacondarwin commentedon Feb 8, 2021
Glad to hear it.
Drop i18n extraction workflow #8020
angular-automatic-lock-bot commentedon Mar 12, 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.