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:
parent
83ace4ed30
commit
92ff6d93eb
@ -51,7 +51,7 @@ export class Xliff2TranslationSerializer implements TranslationSerializer {
|
|||||||
}
|
}
|
||||||
ids.add(id);
|
ids.add(id);
|
||||||
xml.startTag('unit', {id});
|
xml.startTag('unit', {id});
|
||||||
if (message.meaning || message.description) {
|
if (message.meaning || message.description || message.location) {
|
||||||
xml.startTag('notes');
|
xml.startTag('notes');
|
||||||
if (message.location) {
|
if (message.location) {
|
||||||
const {file, start, end} = 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">`,
|
`<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="en-AU">`,
|
||||||
` <file id="ngi18n" original="ng.template">`,
|
` <file id="ngi18n" original="ng.template">`,
|
||||||
` <unit id="3291030485717846467">`,
|
` <unit id="3291030485717846467">`,
|
||||||
|
` <notes>`,
|
||||||
|
` <note category="location">test_files/test.js:2</note>`,
|
||||||
|
` </notes>`,
|
||||||
` <segment>`,
|
` <segment>`,
|
||||||
` <source>Hello, <ph id="0" equiv="PH" disp="name"/>!</source>`,
|
` <source>Hello, <ph id="0" equiv="PH" disp="name"/>!</source>`,
|
||||||
` </segment>`,
|
` </segment>`,
|
||||||
` </unit>`,
|
` </unit>`,
|
||||||
` <unit id="8669027859022295761">`,
|
` <unit id="8669027859022295761">`,
|
||||||
|
` <notes>`,
|
||||||
|
` <note category="location">test_files/test.js:3</note>`,
|
||||||
|
` </notes>`,
|
||||||
` <segment>`,
|
` <segment>`,
|
||||||
` <source>try<ph id="0" equiv="PH" disp="40 + 2"/>me</source>`,
|
` <source>try<ph id="0" equiv="PH" disp="40 + 2"/>me</source>`,
|
||||||
` </segment>`,
|
` </segment>`,
|
||||||
` </unit>`,
|
` </unit>`,
|
||||||
` <unit id="custom-id">`,
|
` <unit id="custom-id">`,
|
||||||
|
` <notes>`,
|
||||||
|
` <note category="location">test_files/test.js:4</note>`,
|
||||||
|
` </notes>`,
|
||||||
` <segment>`,
|
` <segment>`,
|
||||||
` <source>Custom id message</source>`,
|
` <source>Custom id message</source>`,
|
||||||
` </segment>`,
|
` </segment>`,
|
||||||
` </unit>`,
|
` </unit>`,
|
||||||
` <unit id="${useLegacyIds ? '12345678901234567890' : '273296103957933077'}">`,
|
` <unit id="${useLegacyIds ? '12345678901234567890' : '273296103957933077'}">`,
|
||||||
|
` <notes>`,
|
||||||
|
` <note category="location">test_files/test.js:6</note>`,
|
||||||
|
` </notes>`,
|
||||||
` <segment>`,
|
` <segment>`,
|
||||||
` <source>Legacy id message</source>`,
|
` <source>Legacy id message</source>`,
|
||||||
` </segment>`,
|
` </segment>`,
|
||||||
` </unit>`,
|
` </unit>`,
|
||||||
` <unit id="custom-id-2">`,
|
` <unit id="custom-id-2">`,
|
||||||
|
` <notes>`,
|
||||||
|
` <note category="location">test_files/test.js:8</note>`,
|
||||||
|
` </notes>`,
|
||||||
` <segment>`,
|
` <segment>`,
|
||||||
` <source>Custom and legacy message</source>`,
|
` <source>Custom and legacy message</source>`,
|
||||||
` </segment>`,
|
` </segment>`,
|
||||||
` </unit>`,
|
` </unit>`,
|
||||||
` <unit id="2932901491976224757">`,
|
` <unit id="2932901491976224757">`,
|
||||||
|
` <notes>`,
|
||||||
|
` <note category="location">test_files/test.js:9,10</note>`,
|
||||||
|
` </notes>`,
|
||||||
` <segment>`,
|
` <segment>`,
|
||||||
` <source>pre<pc id="0" equivStart="START_TAG_SPAN" equivEnd="CLOSE_TAG_SPAN" dispStart="'<span>'" dispEnd="'</span>'">` +
|
` <source>pre<pc id="0" equivStart="START_TAG_SPAN" equivEnd="CLOSE_TAG_SPAN" dispStart="'<span>'" dispEnd="'</span>'">` +
|
||||||
`inner-pre<pc id="1" equivStart="START_BOLD_TEXT" equivEnd="CLOSE_BOLD_TEXT" dispStart="'<b>'" dispEnd="'</b>'">bold</pc>` +
|
`inner-pre<pc id="1" equivStart="START_BOLD_TEXT" equivEnd="CLOSE_BOLD_TEXT" dispStart="'<b>'" dispEnd="'</b>'">bold</pc>` +
|
||||||
|
@ -49,6 +49,13 @@ runInEachFileSystem(() => {
|
|||||||
mockMessage(
|
mockMessage(
|
||||||
'67890', ['a', '', 'c'], ['START_TAG_SPAN', 'CLOSE_TAG_SPAN'],
|
'67890', ['a', '', 'c'], ['START_TAG_SPAN', 'CLOSE_TAG_SPAN'],
|
||||||
{description: 'some description'}),
|
{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('13579', ['', 'b', ''], ['START_BOLD_TEXT', 'CLOSE_BOLD_TEXT'], {}),
|
||||||
mockMessage('24680', ['a'], [], {meaning: 'meaning', description: 'and description'}),
|
mockMessage('24680', ['a'], [], {meaning: 'meaning', description: 'and description'}),
|
||||||
mockMessage('80808', ['multi\nlines'], [], {}),
|
mockMessage('80808', ['multi\nlines'], [], {}),
|
||||||
@ -91,6 +98,13 @@ runInEachFileSystem(() => {
|
|||||||
` <source>a<x id="START_TAG_SPAN"/><x id="CLOSE_TAG_SPAN"/>c</source>`,
|
` <source>a<x id="START_TAG_SPAN"/><x id="CLOSE_TAG_SPAN"/>c</source>`,
|
||||||
` <note priority="1" from="description">some description</note>`,
|
` <note priority="1" from="description">some description</note>`,
|
||||||
` </trans-unit>`,
|
` </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">`,
|
` <trans-unit id="13579" datatype="html">`,
|
||||||
` <source><x id="START_BOLD_TEXT"/>b<x id="CLOSE_BOLD_TEXT"/></source>`,
|
` <source><x id="START_BOLD_TEXT"/>b<x id="CLOSE_BOLD_TEXT"/></source>`,
|
||||||
` </trans-unit>`,
|
` </trans-unit>`,
|
||||||
|
@ -54,6 +54,13 @@ runInEachFileSystem(() => {
|
|||||||
end: {line: 3, column: 2}
|
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('13579', ['', 'b', ''], ['START_BOLD_TEXT', 'CLOSE_BOLD_TEXT'], {}),
|
||||||
mockMessage('24680', ['a'], [], {meaning: 'meaning', description: 'and description'}),
|
mockMessage('24680', ['a'], [], {meaning: 'meaning', description: 'and description'}),
|
||||||
mockMessage('80808', ['multi\nlines'], [], {}),
|
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>`,
|
` <source>a<pc id="0" equivStart="START_TAG_SPAN" equivEnd="CLOSE_TAG_SPAN"></pc>c</source>`,
|
||||||
` </segment>`,
|
` </segment>`,
|
||||||
` </unit>`,
|
` </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">`,
|
` <unit id="13579">`,
|
||||||
` <segment>`,
|
` <segment>`,
|
||||||
` <source><pc id="0" equivStart="START_BOLD_TEXT" equivEnd="CLOSE_BOLD_TEXT">b</pc></source>`,
|
` <source><pc id="0" equivStart="START_BOLD_TEXT" equivEnd="CLOSE_BOLD_TEXT">b</pc></source>`,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user