fix(compiler): i18n - ignore `alt-trans` tags in XLIFF 1.2 (#33450)
The parser was accidentally reading the `target` tag below the `alt-trans` target and overriding the correct `target` tag. (This already worked in `$localize` but a test has been added to confirm.) Fixes #33161 PR Close #33450
This commit is contained in:
parent
a3034ef92e
commit
936700ad9f
|
@ -25,6 +25,7 @@ const _MARKER_TAG = 'mrk';
|
||||||
const _FILE_TAG = 'file';
|
const _FILE_TAG = 'file';
|
||||||
const _SOURCE_TAG = 'source';
|
const _SOURCE_TAG = 'source';
|
||||||
const _SEGMENT_SOURCE_TAG = 'seg-source';
|
const _SEGMENT_SOURCE_TAG = 'seg-source';
|
||||||
|
const _ALT_TRANS_TAG = 'alt-trans';
|
||||||
const _TARGET_TAG = 'target';
|
const _TARGET_TAG = 'target';
|
||||||
const _UNIT_TAG = 'trans-unit';
|
const _UNIT_TAG = 'trans-unit';
|
||||||
const _CONTEXT_GROUP_TAG = 'context-group';
|
const _CONTEXT_GROUP_TAG = 'context-group';
|
||||||
|
@ -222,6 +223,7 @@ class XliffParser implements ml.Visitor {
|
||||||
// ignore those tags
|
// ignore those tags
|
||||||
case _SOURCE_TAG:
|
case _SOURCE_TAG:
|
||||||
case _SEGMENT_SOURCE_TAG:
|
case _SEGMENT_SOURCE_TAG:
|
||||||
|
case _ALT_TRANS_TAG:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case _TARGET_TAG:
|
case _TARGET_TAG:
|
||||||
|
|
|
@ -296,6 +296,30 @@ lignes`,
|
||||||
it('should return the target locale',
|
it('should return the target locale',
|
||||||
() => { expect(serializer.load(LOAD_XLIFF, 'url').locale).toEqual('fr'); });
|
() => { expect(serializer.load(LOAD_XLIFF, 'url').locale).toEqual('fr'); });
|
||||||
|
|
||||||
|
it('should ignore alt-trans targets', () => {
|
||||||
|
const XLIFF = `
|
||||||
|
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
|
||||||
|
<file source-language="en" target-language="fr" datatype="plaintext" original="ng2.template">
|
||||||
|
<body>
|
||||||
|
<trans-unit datatype="html" approved="no" id="registration.submit">
|
||||||
|
<source>Continue</source>
|
||||||
|
<target state="translated" xml:lang="de">Weiter</target>
|
||||||
|
<context-group purpose="location">
|
||||||
|
<context context-type="sourcefile">src/app/auth/registration-form/registration-form.component.html</context>
|
||||||
|
<context context-type="linenumber">69</context>
|
||||||
|
</context-group>
|
||||||
|
<?sid 1110954287-0?>
|
||||||
|
<alt-trans origin="autoFuzzy" tool="Swordfish" match-quality="71" ts="63">
|
||||||
|
<source xml:lang="en">Content</source>
|
||||||
|
<target state="translated" xml:lang="de">Content</target>
|
||||||
|
</alt-trans>
|
||||||
|
</trans-unit>
|
||||||
|
</body>
|
||||||
|
</file>
|
||||||
|
</xliff>`;
|
||||||
|
|
||||||
|
expect(loadAsMap(XLIFF)).toEqual({'registration.submit': 'Weiter'});
|
||||||
|
});
|
||||||
|
|
||||||
describe('structure errors', () => {
|
describe('structure errors', () => {
|
||||||
it('should throw when a trans-unit has no translation', () => {
|
it('should throw when a trans-unit has no translation', () => {
|
||||||
|
|
|
@ -373,6 +373,34 @@ describe('Xliff1TranslationParser', () => {
|
||||||
.toEqual(ɵmakeParsedTranslation(['Translated first sentence.']));
|
.toEqual(ɵmakeParsedTranslation(['Translated first sentence.']));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should ignore alt-trans targets', () => {
|
||||||
|
const XLIFF = `
|
||||||
|
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
|
||||||
|
<file source-language="en" target-language="fr" datatype="plaintext" original="ng2.template">
|
||||||
|
<body>
|
||||||
|
<trans-unit datatype="html" approved="no" id="registration.submit">
|
||||||
|
<source>Continue</source>
|
||||||
|
<target state="translated" xml:lang="de">Weiter</target>
|
||||||
|
<context-group purpose="location">
|
||||||
|
<context context-type="sourcefile">src/app/auth/registration-form/registration-form.component.html</context>
|
||||||
|
<context context-type="linenumber">69</context>
|
||||||
|
</context-group>
|
||||||
|
<?sid 1110954287-0?>
|
||||||
|
<alt-trans origin="autoFuzzy" tool="Swordfish" match-quality="71" ts="63">
|
||||||
|
<source xml:lang="en">Content</source>
|
||||||
|
<target state="translated" xml:lang="de">Content</target>
|
||||||
|
</alt-trans>
|
||||||
|
</trans-unit>
|
||||||
|
</body>
|
||||||
|
</file>
|
||||||
|
</xliff>`;
|
||||||
|
|
||||||
|
const parser = new Xliff1TranslationParser();
|
||||||
|
const result = parser.parse('/some/file.xlf', XLIFF);
|
||||||
|
expect(result.translations['registration.submit'])
|
||||||
|
.toEqual(ɵmakeParsedTranslation(['Weiter']));
|
||||||
|
});
|
||||||
|
|
||||||
describe('[structure errors]', () => {
|
describe('[structure errors]', () => {
|
||||||
it('should throw when a trans-unit has no translation', () => {
|
it('should throw when a trans-unit has no translation', () => {
|
||||||
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
const XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
|
Loading…
Reference in New Issue