From 936700ad9f94c42ed59e4aebd3a21ffe0efe54bb Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Mon, 28 Oct 2019 20:19:27 +0000 Subject: [PATCH] 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 --- .../compiler/src/i18n/serializers/xliff.ts | 2 ++ .../test/i18n/serializers/xliff_spec.ts | 24 ++++++++++++++++ .../xliff1_translation_parser_spec.ts | 28 +++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/packages/compiler/src/i18n/serializers/xliff.ts b/packages/compiler/src/i18n/serializers/xliff.ts index 58d9a6083c..b546ce14e1 100644 --- a/packages/compiler/src/i18n/serializers/xliff.ts +++ b/packages/compiler/src/i18n/serializers/xliff.ts @@ -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'; @@ -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: diff --git a/packages/compiler/test/i18n/serializers/xliff_spec.ts b/packages/compiler/test/i18n/serializers/xliff_spec.ts index 87c153b633..99ee251a57 100644 --- a/packages/compiler/test/i18n/serializers/xliff_spec.ts +++ b/packages/compiler/test/i18n/serializers/xliff_spec.ts @@ -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 = ` + + + + + Continue + Weiter + + src/app/auth/registration-form/registration-form.component.html + 69 + + + + Content + Content + + + + + `; + + expect(loadAsMap(XLIFF)).toEqual({'registration.submit': 'Weiter'}); + }); describe('structure errors', () => { it('should throw when a trans-unit has no translation', () => { diff --git a/packages/localize/src/tools/test/translate/translation_files/translation_parsers/xliff1_translation_parser_spec.ts b/packages/localize/src/tools/test/translate/translation_files/translation_parsers/xliff1_translation_parser_spec.ts index e0fa2a443c..4a4c2268a7 100644 --- a/packages/localize/src/tools/test/translate/translation_files/translation_parsers/xliff1_translation_parser_spec.ts +++ b/packages/localize/src/tools/test/translate/translation_files/translation_parsers/xliff1_translation_parser_spec.ts @@ -373,6 +373,34 @@ describe('Xliff1TranslationParser', () => { .toEqual(ɵmakeParsedTranslation(['Translated first sentence.'])); }); + it('should ignore alt-trans targets', () => { + const XLIFF = ` + + + + + Continue + Weiter + + src/app/auth/registration-form/registration-form.component.html + 69 + + + + Content + Content + + + + + `; + + const parser = new Xliff1TranslationParser(); + const result = parser.parse('/some/file.xlf', XLIFF); + expect(result.translations['registration.submit']) + .toEqual(ɵmakeParsedTranslation(['Weiter'])); + }); + describe('[structure errors]', () => { it('should throw when a trans-unit has no translation', () => { const XLIFF = `