-
Notifications
You must be signed in to change notification settings - Fork 12k
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
i18n support in Angular libraries #17140
Comments
Hi @multimike77, thanks for reporting this. The docs seems to be incorrect as i18n extraction is only supported at application level. |
Thanks, I thought already that it could be like this. Then I will adjust my expectations for now. Overall scenrio would be like that:
From what I understood from the docs around i18n and ivy in Angular 9, i18n tags are extracted when used in an application. But like this, every application which uses the library will need to provide own translations for the texts used in the library components. This is of course not ideal in regards to reusability. |
@clydin would know more about this topic.
I think there are two sides of this, you can also say that the library author shouldn't be responsible for the translations themselves, but only provide a way to localise the library. Though I do understand that this feature might be useful in some cases. |
In the next few weeks (hopefully) I will be working on new translation extraction tooling that understands the new
|
In our case it's like several shared components and libraries which are used in multiple applications created by different teams throughout the company. The texts and translations for the library components should only be done once and be the same across the applications.
This sounds promising @petebacondarwin ! |
@petebacondarwin just to know about timings, are we going to see library extraction tool for angular 10 or before? |
That's my plan! But it will be tight. |
@petebacondarwin: Is there a way to track the progress for these features? |
@michaelhunziker - I have not made much progress. You can follow the various PRs that are in flight can be seen at https://github.com/angular/angular/pulls?q=is%3Apr+is%3Aopen+label%3A%22comp%3A+i18n%22+ |
@petebacondarwin - is there a way I could use a cmd like localize-translate to do what ng xi18n does? I tried below command, but it still requires -t which is looking for translated files and don't have these files yet. I want to extract i18n attributes in the HTML to messages.xlf. I need to do this in Angular 10.0.3 (localize-extract is not supported). It is okay if just HTML messages get into the messages.xlf file. Please let me know if there is a work around? node_modules/.bin/localize-translate --root=dist/libs/my-lib --source=bundles/**/* -o projects/libs/my-lib/src/locale/ |
@sistla001 - yes. It is called tsc -p tsconfig.app.json
node_modules/.bin/localize-extract -s "out-tsc/**/*.js" -f xlf -o message.xlf |
yeah, but localize-extract is not included with cli 10.0.3, is there an equivalent command that I can use in 10.0.3 library project? |
It is available in |
@petebacondarwin what is the right way to extract messages from the library in Angular 11.0.0?
and then I've tried command:
|
Extracting library messages via CLI is not yet supported. You could use |
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends. Find more details about Angular's feature request process in our documentation. |
It's good to see some movement here with the voting process. Despite having localize-extract as a workaround, it would be great to have some permanent and standardized solution included in the cli tooling. Localize-extract was working fine for me so far, although sometimes seems to miss to extract some keys. When running the main app, which then includes the xlf file generated for the library, the warnings for missing keys do show up on console. |
Sadly this feature is required only by ten developers, not enough I guess. |
then at least 11 |
I am on angular 13, and I spent all the morning trying to figure out why the Btw, having this bundled in the cli would help. |
For anyone else wondering: I had to create another configuration in
The project was used to specify a different directory (to avoid overriding existing dists), and in the tsConfig the important options are:
Especially the last one, because Angular sets it to true by default for libraries, this was my problem |
What about libraries that are needed to be published to registries? It says, they have to have compilationMode=partial, otherwise I get an error that it can't be published. |
You use this configuration only to extract translation strings, if you wanna publish your library you recompile it in partial mode with another configuration |
Ok, this may work for the libraries we own. But, any ideas on how texts can be extracted from Kendo/3rd party Libraries? here's the command that used to work with Angular 10 and no longer works after upgrading to angular 14.
Update: |
Wanted to comment for visibility. I'm working on a project that use a monorepo with multiples apps/projects where we want to make use of incremental builds. To do so, our library needs to We don't seems to have any issue with it so far, but would like to understand more about potential issues about it. Are there any known best practices for libraries translation as this issue seems blocked for a long time now. |
We also use |
Here is an old discussion about library (APF format) and i18n: angular/angular#38366 (comment) Basically, on my teams, we have more than 100 library projects with translations packed inside plus a schematic that just merge strings from libraries used to xlif file produced by the final app. Just a custom way to make it possible to distribute translations near the library. Another approach is the one chosen by Kendo UI, which just has a big library with all strings from all components plus a script that merge strings on xlif. What we would like to expect is to have
I mean, it is something that we do every day with a custom "build pipeline" but I guess a goal is to propose an official approach to cover this need, mainly for small libraries and not-so-big teams. My two cents. |
Pretty sure this is solved already, because it turns out that So basically something like that: {
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"projects": {
// ... other things here...
"my-project": {
"i18n": {
"locales": {
"en": [
"node_modules/my-library/i18n/messages.en.xlf",
"client/i18n/messages.en.xlf"
],
"es": [
"node_modules/my-library/i18n/messages.es.xlf",
"client/i18n/messages.es.xlf"
]
}
}
}
}
} |
Yes @PowerKiKi locale now supports merging multiple xlif files on angular.json, the main problem is extraction and packing them Thanks for the tip! |
I think we can create a new playground app for each library and perform extraction operations there |
I have a project with 180 libraries! I can't follow that approach. |
Is there any news on that topic? If I follow your tip and add "extract-i18n" in the architects section of my lib. But I get the following message by now:
So translating libraries isn't supported at all, although it is allegedly supported? https://v18.angular.dev/cli/extract-i18n |
🐞 Bug report
Command (mark with an
x
)Is this a regression?
No. Related functionaliy only available with new i18n capabilities of angular 9.Description
I want to use ng xi18n command to extract messages for i18n tags which are part of a library project which is part of a monrepo setup created by the cli. According to docs athttps://angular.io/cli/xi18n this is supposed to be possible
🔬 Minimal Reproduction
ng new lib-i18n
ng add @angular/localize
ng g library my-lib
ng xi18n my-lib
: Result will beAn unhandled exception occurred: Project 'my-lib' does not support the 'extract-i18n' target.
After adding corresponding extract-i18n target in angular.json, error output as below.
I created a minimal demo project which incorporates the scenario describe above. It is located here:
https://github.com/multimike77/lib-i18n-issue
Checkout and run
npm install
. Then runng xi18n my-lib
and it should produce error as below.🔥 Exception or Error
🌍 Your Environment
Anything else relevant?
The text was updated successfully, but these errors were encountered: