Skip to content

Commit

Permalink
fix: do not change translation state for non-updates (changes only in…
Browse files Browse the repository at this point in the history
… collapsible whitespace)
  • Loading branch information
daniel-sc committed Jul 20, 2022
1 parent e3d629c commit 83f1780
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions __tests__/merge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,41 @@ describe('merge', () => {
'</xliff>'));
});

test('should not update node with only collapsible whitespace change', () => {
const sourceFileContent = '<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="de">\n' +
' <file original="ng.template" id="ngi18n">\n' +
' <unit id="ID1">\n' +
' <segment>\n' +
' <source> source val </source>\n' +
' </segment>\n' +
' </unit>\n' +
' </file>\n' +
'</xliff>';
const destFileContent = '<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="de" trgLang="fr-CH">\n' +
' <file original="ng.template" id="ngi18n">\n' +
' <unit id="ID1">\n' +
' <segment state="translated">\n' +
' <source> source val </source>\n' +
' <target>target val</target>\n' +
' </segment>\n' +
' </unit>\n' +
' </file>\n' +
'</xliff>';

const result = merge(sourceFileContent, destFileContent);

expect(norm(result)).toEqual(norm('<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="de" trgLang="fr-CH">\n' +
' <file original="ng.template" id="ngi18n">\n' +
' <unit id="ID1">\n' +
' <segment state="translated">\n' +
' <source> source val </source>\n' +
' <target>target val</target>\n' +
' </segment>\n' +
' </unit>\n' +
' </file>\n' +
'</xliff>'));
});

test('should update changed node without updating translation state if disabled', () => {
const sourceFileContent = '<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="de">\n' +
' <file original="ng.template" id="ngi18n">\n' +
Expand Down
2 changes: 1 addition & 1 deletion src/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function toString(...nodes: XmlNode[]): string {
}

function collapseWhitespace(destSourceText: string) {
return destSourceText.replace(/\s+/, ' ');
return destSourceText.replace(/\s+/g, ' ');
}

function getUnits(doc: XmlDocument, xliffVersion: '1.2' | '2.0') {
Expand Down

0 comments on commit 83f1780

Please sign in to comment.