fix(compiler): fix i18n IDs generation, add a migration tool #17638
fix(compiler): fix i18n IDs generation, add a migration tool #17638ocombe wants to merge 15 commits intoangular:masterfrom
Conversation
There was a problem hiding this comment.
- Should we throw in this case ?
- change param to
i18nFormat: string | null?
There was a problem hiding this comment.
nit: this is not the startOfEl - add a comment ?
better: extract content.lastIndexOf('>', sources[0].startSourceSpan !.start.offset) + 1 to an helper function to factorize, add doc there
There was a problem hiding this comment.
What are start and end used for ?
Would your logic work if source elements are not back to back
<source>1</source>
<other>
<source>2</source>
There was a problem hiding this comment.
good point, it would fail :(
There was a problem hiding this comment.
Unused but required since we extend ml.RecursiveVisitor.
There was a problem hiding this comment.
- using
removefor something with is not removed is a bad idea - old1 & old2 ? - be consistent why
mappingand an inline mapping ? use v0ToV1 and v1ToV0
There was a problem hiding this comment.
move this at describe level to avoir repeating ?
There was a problem hiding this comment.
why do we have to change the tsconfig here ?
There was a problem hiding this comment.
because of a change that @tbosch made on master, without these parameters the tests won't work
There was a problem hiding this comment.
I'd rather have execute and generateMapping()
There was a problem hiding this comment.
Did you create an issue for this bug as discussed in the shared doc ? (startCol = endCol)
There was a problem hiding this comment.
remove ? from here for consistency
There was a problem hiding this comment.
Should be el.visit(this, null);
There was a problem hiding this comment.
sourcesInfos -> srcElements ?
There was a problem hiding this comment.
probably you should merge SourceInfosVisitor with MsgInfosVisitor ?
There was a problem hiding this comment.
wouldn't replacing the id (right above) shift the sourcespan for the sources ?
If yes, why is this not caught by the tests.
There was a problem hiding this comment.
because in my test the "old" id and the "new" id have the same length. Replacing "old" by "old2" made the tests fail
There was a problem hiding this comment.
maybe use constants here const XLIFF_MSG_EL = 'trans-unit';
|
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
|
You can preview 6409883 at https://pr17638-6409883.ngbuilds.io/. |
fixes angular#15573 `I18nVersion.Version1` fixes several bugs in the serializers. `I18nVersion.Version0` is identical to the behavior prior to this PR.
`i18nVersion` could be '0' or '1'
using `-i18nVersion=1`
|
You can preview 9d366bb at https://pr17638-9d366bb.ngbuilds.io/. |
a3bb636 to
ccb2ae9
Compare
|
Closing this for now because it's completely out of date and our code has changed too much. We'll have to start over if we want to fix this problem. |
|
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. |
Please check if the PR fulfills these requirements
What kind of change does this PR introduce?
What is the current behavior?
See #15573.
What is the new behavior?
When we extract messages we digest them to generate ids (unless the id is provided).
With this fix we ignore the content of the placeholder when we digest to only use the fact that it's a placeholder and its position.
We already did the same thing with ICU expressions for XMB and this previous fix is now also applied to ICU expressions for XLIFF (now that XLIFF supports ICU expressions).
Example previously
<p i18n>{{expr}}</p>,<p i18n>{{ expr }}</p>and<p i18n>{{expr2}}</p>had different ids but the exact same content once extracted. With this fix those 3 messages will only be extracted once with the same id.We also aligned the digest functions for all serializers, they will all use the decimal digest (instead of sha1 previously for xliff).
Because of the bug #15573 we had to make a breaking change in the way i18n ids are generated.
To mitigate the problem, a new flag can be used to set the version of the digest method used:
--i18nVersionwith values 0 (old, default for v4) or 1 (new, default for v5) can be used by the cli tools for extraction (ng-xi18n) and AOT (ngc). The tokenI18N_VERSIONcan be used in your code for JIT.We also added a new migration cli tool in @angular/compiler-cli named ng-migrate-i18n-0to1.
Usage is the following:
ng-migrate-i18n-0to1 --files src/i18n/*.xlf --format xlf--files: (required) the translation files that you want to migrate, you can use glob expressions to migrate multiple files at the same time (as long as they use the same format)
--format: (required) the format of the translation files that you want to migrate
--mapping: (optional) if you add this option it will generate a json file of mappings {newId --> [oldIds]} instead of migrating the translation files
--resolve: (optional) "manual" by default, you can use "auto" so that the cli tool doesn't ask when it finds conflicts (in which case it will take the first value)
Does this PR introduce a breaking change?
Unfortunately this is a breaking change because the auto-generated ids for extracted messages will change if the message contains placeholders (or ICU expressions for XLIFF)...
To mitigate the problem, a new flag can be used to set the version of the digest method used. It is
--i18nVersionwith values 0 (old, default for v4) or 1 (new, default for v5) for ngc, and the tokenI18N_VERSIONfor JIT.For now we still use the old method to generate the ids, but once v5 is released we will reverse the flag to only use the new version.