fix(localize): render location in XLIFF 2 even if there is no metadata (#38713)

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

PR Close #38713
This commit is contained in:
Pete Bacon Darwin
2020-09-04 15:16:12 +01:00
committed by atscott
parent 83ace4ed30
commit 92ff6d93eb
4 changed files with 48 additions and 1 deletions
@@ -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;
@@ -220,31 +220,49 @@ runInEachFileSystem(() => {
`<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="en-AU">`,
` <file id="ngi18n" original="ng.template">`,
` <unit id="3291030485717846467">`,
` <notes>`,
` <note category="location">test_files/test.js:2</note>`,
` </notes>`,
` <segment>`,
` <source>Hello, <ph id="0" equiv="PH" disp="name"/>!</source>`,
` </segment>`,
` </unit>`,
` <unit id="8669027859022295761">`,
` <notes>`,
` <note category="location">test_files/test.js:3</note>`,
` </notes>`,
` <segment>`,
` <source>try<ph id="0" equiv="PH" disp="40 + 2"/>me</source>`,
` </segment>`,
` </unit>`,
` <unit id="custom-id">`,
` <notes>`,
` <note category="location">test_files/test.js:4</note>`,
` </notes>`,
` <segment>`,
` <source>Custom id message</source>`,
` </segment>`,
` </unit>`,
` <unit id="${useLegacyIds ? '12345678901234567890' : '273296103957933077'}">`,
` <notes>`,
` <note category="location">test_files/test.js:6</note>`,
` </notes>`,
` <segment>`,
` <source>Legacy id message</source>`,
` </segment>`,
` </unit>`,
` <unit id="custom-id-2">`,
` <notes>`,
` <note category="location">test_files/test.js:8</note>`,
` </notes>`,
` <segment>`,
` <source>Custom and legacy message</source>`,
` </segment>`,
` </unit>`,
` <unit id="2932901491976224757">`,
` <notes>`,
` <note category="location">test_files/test.js:9,10</note>`,
` </notes>`,
` <segment>`,
` <source>pre<pc id="0" equivStart="START_TAG_SPAN" equivEnd="CLOSE_TAG_SPAN" dispStart="&apos;&lt;span&gt;&apos;" dispEnd="&apos;&lt;/span&gt;&apos;">` +
`inner-pre<pc id="1" equivStart="START_BOLD_TEXT" equivEnd="CLOSE_BOLD_TEXT" dispStart="&apos;&lt;b&gt;&apos;" dispEnd="&apos;&lt;/b&gt;&apos;">bold</pc>` +
@@ -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(() => {
` <source>a<x id="START_TAG_SPAN"/><x id="CLOSE_TAG_SPAN"/>c</source>`,
` <note priority="1" from="description">some description</note>`,
` </trans-unit>`,
` <trans-unit id="38705" datatype="html">`,
` <source>a<x id="START_TAG_SPAN"/><x id="CLOSE_TAG_SPAN"/>c</source>`,
` <context-group purpose="location">`,
` <context context-type="sourcefile">file.ts</context>`,
` <context context-type="linenumber">3,4</context>`,
` </context-group>`,
` </trans-unit>`,
` <trans-unit id="13579" datatype="html">`,
` <source><x id="START_BOLD_TEXT"/>b<x id="CLOSE_BOLD_TEXT"/></source>`,
` </trans-unit>`,
@@ -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(() => {
` <source>a<pc id="0" equivStart="START_TAG_SPAN" equivEnd="CLOSE_TAG_SPAN"></pc>c</source>`,
` </segment>`,
` </unit>`,
` <unit id="location-only">`,
` <notes>`,
` <note category="location">file.ts:3,4</note>`,
` </notes>`,
` <segment>`,
` <source>a<pc id="0" equivStart="START_TAG_SPAN" equivEnd="CLOSE_TAG_SPAN"></pc>c</source>`,
` </segment>`,
` </unit>`,
` <unit id="13579">`,
` <segment>`,
` <source><pc id="0" equivStart="START_BOLD_TEXT" equivEnd="CLOSE_BOLD_TEXT">b</pc></source>`,