From 1489cc3b30a2191498793a4b23c48c84b3beb4bc Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Fri, 4 Sep 2020 15:16:12 +0100 Subject: [PATCH] fix(localize): render location in XLIFF 2 even if there is no metadata Previously, the location of a translation message, in XLIFF 2, was only rendered if there were also notes for meaning or description. Now the location will be rendered even if the other metadata is not provided. Fixes #38705 --- .../xliff2_translation_serializer.ts | 2 +- .../test/extract/integration/main_spec.ts | 18 ++++++++++++++++++ .../xliff1_translation_serializer_spec.ts | 14 ++++++++++++++ .../xliff2_translation_serializer_spec.ts | 15 +++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/packages/localize/src/tools/src/extract/translation_files/xliff2_translation_serializer.ts b/packages/localize/src/tools/src/extract/translation_files/xliff2_translation_serializer.ts index 4dd7e4f4a2824..6dafa6a5d5dc6 100644 --- a/packages/localize/src/tools/src/extract/translation_files/xliff2_translation_serializer.ts +++ b/packages/localize/src/tools/src/extract/translation_files/xliff2_translation_serializer.ts @@ -51,7 +51,7 @@ export class Xliff2TranslationSerializer implements TranslationSerializer { } ids.add(id); xml.startTag('unit', {id}); - if (message.meaning || message.description) { + if (message.meaning || message.description || message.location) { xml.startTag('notes'); if (message.location) { const {file, start, end} = message.location; diff --git a/packages/localize/src/tools/test/extract/integration/main_spec.ts b/packages/localize/src/tools/test/extract/integration/main_spec.ts index 3f69a2d22f215..07f89aa5c4540 100644 --- a/packages/localize/src/tools/test/extract/integration/main_spec.ts +++ b/packages/localize/src/tools/test/extract/integration/main_spec.ts @@ -220,31 +220,49 @@ runInEachFileSystem(() => { ``, ` `, ` `, + ` `, + ` test_files/test.js:2`, + ` `, ` `, ` Hello, !`, ` `, ` `, ` `, + ` `, + ` test_files/test.js:3`, + ` `, ` `, ` tryme`, ` `, ` `, ` `, + ` `, + ` test_files/test.js:4`, + ` `, ` `, ` Custom id message`, ` `, ` `, ` `, + ` `, + ` test_files/test.js:6`, + ` `, ` `, ` Legacy id message`, ` `, ` `, ` `, + ` `, + ` test_files/test.js:8`, + ` `, ` `, ` Custom and legacy message`, ` `, ` `, ` `, + ` `, + ` test_files/test.js:9,10`, + ` `, ` `, ` pre` + `inner-prebold` + diff --git a/packages/localize/src/tools/test/extract/translation_files/xliff1_translation_serializer_spec.ts b/packages/localize/src/tools/test/extract/translation_files/xliff1_translation_serializer_spec.ts index f421850a3270e..4a9e8baa89594 100644 --- a/packages/localize/src/tools/test/extract/translation_files/xliff1_translation_serializer_spec.ts +++ b/packages/localize/src/tools/test/extract/translation_files/xliff1_translation_serializer_spec.ts @@ -49,6 +49,13 @@ runInEachFileSystem(() => { mockMessage( '67890', ['a', '', 'c'], ['START_TAG_SPAN', 'CLOSE_TAG_SPAN'], {description: 'some description'}), + mockMessage('38705', ['a', '', 'c'], ['START_TAG_SPAN', 'CLOSE_TAG_SPAN'], { + location: { + file: absoluteFrom('/project/file.ts'), + start: {line: 2, column: 7}, + end: {line: 3, column: 2} + } + }), mockMessage('13579', ['', 'b', ''], ['START_BOLD_TEXT', 'CLOSE_BOLD_TEXT'], {}), mockMessage('24680', ['a'], [], {meaning: 'meaning', description: 'and description'}), mockMessage('80808', ['multi\nlines'], [], {}), @@ -91,6 +98,13 @@ runInEachFileSystem(() => { ` ac`, ` some description`, ` `, + ` `, + ` ac`, + ` `, + ` file.ts`, + ` 3,4`, + ` `, + ` `, ` `, ` b`, ` `, diff --git a/packages/localize/src/tools/test/extract/translation_files/xliff2_translation_serializer_spec.ts b/packages/localize/src/tools/test/extract/translation_files/xliff2_translation_serializer_spec.ts index d783e0ce9f914..d01b6d0ca3f40 100644 --- a/packages/localize/src/tools/test/extract/translation_files/xliff2_translation_serializer_spec.ts +++ b/packages/localize/src/tools/test/extract/translation_files/xliff2_translation_serializer_spec.ts @@ -54,6 +54,13 @@ runInEachFileSystem(() => { end: {line: 3, column: 2} } }), + mockMessage('location-only', ['a', '', 'c'], ['START_TAG_SPAN', 'CLOSE_TAG_SPAN'], { + location: { + file: absoluteFrom('/project/file.ts'), + start: {line: 2, column: 7}, + end: {line: 3, column: 2} + } + }), mockMessage('13579', ['', 'b', ''], ['START_BOLD_TEXT', 'CLOSE_BOLD_TEXT'], {}), mockMessage('24680', ['a'], [], {meaning: 'meaning', description: 'and description'}), mockMessage('80808', ['multi\nlines'], [], {}), @@ -101,6 +108,14 @@ runInEachFileSystem(() => { ` ac`, ` `, ` `, + ` `, + ` `, + ` file.ts:3,4`, + ` `, + ` `, + ` ac`, + ` `, + ` `, ` `, ` `, ` b`,