Skip to content

Commit

Permalink
fix(compiler): i18n - ignore alt-trans tags in XLIFF 1.2 (#33464)
Browse files Browse the repository at this point in the history
The parser was accidentally reading the `target` tag
below the `alt-trans` target and overriding the correct
`target` tag.

Fixes #33161

PR Close #33464
  • Loading branch information
petebacondarwin authored and AndrewKushnir committed Oct 29, 2019
1 parent ac4353c commit f97c464
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/compiler/src/i18n/serializers/xliff.ts
Expand Up @@ -25,6 +25,7 @@ const _MARKER_TAG = 'mrk';
const _FILE_TAG = 'file';
const _SOURCE_TAG = 'source';
const _SEGMENT_SOURCE_TAG = 'seg-source';
const _ALT_TRANS_TAG = 'alt-trans';
const _TARGET_TAG = 'target';
const _UNIT_TAG = 'trans-unit';
const _CONTEXT_GROUP_TAG = 'context-group';
Expand Down Expand Up @@ -222,6 +223,7 @@ class XliffParser implements ml.Visitor {
// ignore those tags
case _SOURCE_TAG:
case _SEGMENT_SOURCE_TAG:
case _ALT_TRANS_TAG:
break;

case _TARGET_TAG:
Expand Down
24 changes: 24 additions & 0 deletions packages/compiler/test/i18n/serializers/xliff_spec.ts
Expand Up @@ -296,6 +296,30 @@ lignes`,
it('should return the target locale',
() => { 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', () => {
it('should throw when a trans-unit has no translation', () => {
Expand Down

0 comments on commit f97c464

Please sign in to comment.