Repository navigation
i18n - extraction tooling - #32912
petebacondarwin wants to merge 7 commits into
Conversation
4020c4a to
9f3d350
Compare
7a3b68a to
093f8d5
Compare
a0d1090 to
bdc258e
Compare
0f90ce5 to
31dc0bd
Compare
31dc0bd to
8122c40
Compare
|
I see 10.1.0 is released, so upgraded my project and did |
|
It appears using the |
|
Extraction from .ts seems working when using |
|
At the moment we are hiding the new extractor behind the @jaska45 - please can you create a new issue with a reproduction of your problem? @sistla001 - currently the new message extractor only looks at the application code - not library code. We need to come up with a proper story for this. In the meantime you could extract them "manually" by running the ivy message extractor directly on the code of the library... Something like: (obviously you will have needed to run ngcc on these libraries fiirst) |
|
Here is what I did to get it to work. I am using xlf-merge to merge kendo-messages.xlf and messages.xlf (project with --ivy flag) into new messages.xlf then using "@ngx-i18nsupport library to generate messages.es.xlf and messages.fr.xlf from messages.xlf. Does @angular/cli already has support to these functionalities? If not, it would be nice if these too were included. |
|
That's really cool @sistla001 I had not been aware of the If Kendo provided these messages in a form that we could use (like XLIFF) then you could short-circuit the extraction process and just merge their translations when building the app: you are able to provide an array of translation files for each locale in the |
Maybe you don't have to merge the files because the i18n/locales attributes in angular.json accept an array of filepath. |
Good to know.. Thanks!! |
|
Is it possible that the meaning and description in the templates are not extracted? The source file also does not appear.
<button i18n="Follow User button|click to follow user@@FollowUser">Follow User</button>give me this result: <unit id="FollowUser">
<segment>
<source>Follow User</source>
</segment>
</unit> const title = $localize`:welcome message|home page title@@HomeTitle:You are Welcome`;this: <unit id="HomeTitle">
<notes>
<note category="location">src/app/main/pages/home/home.component.js:65</note>
<note category="description">home page title</note>
<note category="meaning">welcome message</note>
</notes>
<segment>
<source>You are Welcome</source>
</segment>
</unit> |
|
I just tried that template HTML with the latest Angular and CLI releases (i.e. 10.1.1) and I got: <unit id="FollowUser">
<notes>
<note category="location">src/app/app.component.html:3</note>
<note category="description">click to follow user</note>
<note category="meaning">Follow User button</note>
</notes>
<segment>
<source>Follow User</source>
</segment>
</unit>Can you check your versions @manzonif |
|
@petebacondarwin thanks, now it work correctly. |
|
Is there a way to translate text from [title] from HTML without moving the condition to typescript? There is no reason why I shouldn't move the condition to typescript but just curious to know if there is a way.
I tried - i18n-title but didn't extract any messages. |
|
@sistla001 - We do not support i18n messages on dynamic input bindings. |
|
@sistla001You have to handle the string in .ts code. For example in your component code Then you use the title variable in your template |
|
How about normal plural syntax? Is It still working? So in html title="here some plural syntax" i18n.title="@@someTitle" |
|
@JanneHarju - what do you mean by "plural syntax"? Do you mean a plural ICU expression? e.g. This still works. |
|
@petebacondarwin that is exactly what I ment. And its was answer for @sistla001 when he ask is conditional translation possible. With plural syntax it is possible no need to move code to ts side. |
Thanks @JanneHarju, @petebacondarwin - I always overlooked this plurals. Thanks for pointing out. It works!! |
|
How about documentation? When we get it to angular.io? Thanks. |
|
Good question! I need to work with @aikidave and @kapunahelewong on this. We will also need to nail down the public API as well. |
|
In my migration from Angular 9 to Angular 10, I am trying leverage I noticed that running In order to avoid this situation, I'd like to permanently migrate everything to the new ID format. But I failed to find a way to specify this option to cli tool I did find the ./node_modules/.bin/localize-extract --locale fr --useLegacyIds false --source dist/my-lib/fesm2015/my-lib.js --format xlf --outputPath dist/messages.xlfIs there a more proper way to opt-in the new ID format, without tinkering with low-level things ? |
|
Actually there is! Currently the CLI But If you disable legacy message ids in the Angular compiler it will never generate them in the first place, and so the message extractor will have to use the non-legacy ids. tsconfig.json {
...
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false
}
}Check out this repo: https://github.com/petebacondarwin/issue32912-i18n-no-legacy-test Note that ngcc always enables legacy message ids at the moment, so any localized messages in templates of library components will still have the old message ids. |
|
Thank you for your quick reply. That allowed me to keep using the standard Our library will now ship their own translations as part of their package, and the consuming application will includes the application translation and the library translation, via the array configuration you mentioned in #32912 (comment). So, for us, the ngcc part is irrelevant, but it's always good to know. |
@petebacondarwin, @JanneHarju - So I tried the ICU or the plural syntax. but this doesn't work: It displays the full plural syntax example: |
|
@sistla001 - this is a known issue: #21615 |
|
Is there any angular recommended approach for multi-language support in Angular Libraries? I am thinking of creating messages files for each library and them merge these message files in the SPA. |
|
This is not an official recommendation, but it seems to be working for us. Our lib maintain localized messages (translated via Weblate) and ship them in the package. Then our app consume them with the implicit merging mechanism. Here is an extract of {
"projects": {
"my-app": {
"i18n": {
"sourceLocale": "fr",
"locales": {
"de": [
"node_modules/@ecodev/natural/i18n/messages.de.xlf",
"client/i18n/messages.de.xlf"
],
"it": [
"node_modules/@ecodev/natural/i18n/messages.it.xlf",
"client/i18n/messages.it.xlf"
],
"en": [
"node_modules/@ecodev/natural/i18n/messages.en.xlf",
"client/i18n/messages.en.xlf"
]
}
}
}
}
} |
|
We are looking into ways that these pre-packaged translations in a library can be automatically discovered by the CLI when translating. It would require some specification in the Angular Package Format, I believe. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This PR implements a new message extraction tool, which will eventually be integrated into the CLI.
Sits on top of #37114, which should land first.
FW-2073
Closes #37202