-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Make i18n extractor execution idempotent #39262
Comments
Can I assume that if you do not change the source code then the extracted output is indeed the same from one run to the next? And that the changes to the ordering you see are due to changes to the source code? |
No, it isn't, and that's our main problem... With no changes to the source code I run |
Hmm, I guess this must be due to the async webpack build in the CLI, that can cause source files to be compiled in different orders... |
I'm going to see if I can sort the messages by the file that they are in.... |
@acalvo how are you ordering the result yourself? |
@suer85 once Angular generates the XLIFF, we run a script to sort it an replace the file generated by Angular. This import * as fs from 'fs';
import * as libxmljs from 'libxmljs';
import * as path from 'path';
const i18nDir = process.argv[2];
const ns = 'urn:oasis:names:tc:xliff:document:1.2';
const xmlDoc = libxmljs.parseXml(fs.readFileSync(path.join(i18nDir, 'translation.en.xlf')).toString());
const body = xmlDoc.get('//ns:body', { ns });
const transUnits = body.childNodes() as Array<libxmljs.Element>;
const newBody = new libxmljs.Element(xmlDoc, 'body', '');
newBody.addChild(transUnits[0]);
transUnits.filter(x => x.type() === 'element').sort((a, b) => {
return parseInt(a.attr('id').value(), 10) - parseInt(b.attr('id').value(), 10);
}).forEach(t => {
newBody.addChild(t);
});
newBody.addChild(transUnits[transUnits.length - 1]);
body.replace(newBody);
fs.writeFileSync(path.join(i18nDir, 'translation.en.xlf'), xmlDoc.toString(), 'utf8'); And execute it this way: Hope it helps as a workaround till it's properly solved by the Angular team :) |
Working on it right now! |
…nt order The CLI integration can provide code files in a non-deterministic order, which led to the extracted translation files having messages in a non-consistent order between extractions. This commit fixes this by ensuring that serialized messages are ordered by their location. Fixes angular#39262
…nt order The CLI integration can provide code files in a non-deterministic order, which led to the extracted translation files having messages in a non-consistent order between extractions. This commit fixes this by ensuring that serialized messages are ordered by their location. Fixes angular#39262
Thanks :) |
Do you have an ETA for a release where this fix is included? |
@JonasSamuelsson - the PR is marked for merging into "patch" so it will appear in 11.0.6 very early in 2021. |
…nt order The CLI integration can provide code files in a non-deterministic order, which led to the extracted translation files having messages in a non-consistent order between extractions. This commit fixes this by ensuring that serialized messages are ordered by their location. Fixes angular#39262
Is it already very early in 2021? :) |
Very very early! Happy New Year. |
…nt order The CLI integration can provide code files in a non-deterministic order, which led to the extracted translation files having messages in a non-consistent order between extractions. This commit fixes this by ensuring that serialized messages are ordered by their location. Fixes angular#39262
Thanks for the fix @petebacondarwin ! 😄 Just a quick clarification:
This didn't happen, did it? I'm seeing in the Angular changelog that it landed in 11.1.0-next.4 but not in 11.0.6. And the changelog seems to be OK because I just tried it and the old behavior keeps happening in 11.0.6. This is not a complain - I just wanted to prevent confusion to the people following this issue, as it seems that it'll be included in the 11.1.x branch and not in the 11.0.x line :). |
Hi @acalvo - it turned out that there was a conflict in merging that PR into the patch branch. Since we are about to release 11.1.0 RC we decided that it was simplest to only merge the PR into the master branch, which means that the fix will be available in 11.1.0. Sorry about the confusion. |
Perfect! No worries - I'm sure we all can wait a few weeks till 11.1.0 goes stable 😊 Thanks again. |
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. |
🚀 feature request
Relevant Package
This feature request is for @angular/localize
Description
Each time you run
ng xi18n --ivy
, the output changes, as the order of thetrans-unit
s is different from execution to execution.Describe the solution you'd like
The output could be sorted (in any way) to ensure that if the source code doesn't change, the output is always the same. This would make it easier to see the changes in the version control system, etc.
Describe alternatives you've considered
Meanwhile, we are ordering the resulting XLIFF by ourselves.
The text was updated successfully, but these errors were encountered: