Skip to content

Commit

Permalink
fix: remove description and meaning if includeContext is false/default
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sc committed Oct 28, 2023
1 parent a356c11 commit 93f08b2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ describe('Builder', () => {
format: 'xlf',
targetFiles: ['messages.fr.xlf'],
outputPath: 'builder-test',
includeContext: true,
removeIdsWithPrefix: ['removeMe']
},
messagesFrExpected: '<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">\n' +
Expand Down Expand Up @@ -1620,6 +1621,37 @@ describe('Builder', () => {
'</xliff>',
})

});
test('remove context in messages source file when includeContext=false and format=xlf2', async () => {
await runTest({
messagesBefore: '<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="de">\n' +
' <file id="ngi18n" original="ng.template">\n' +
' <unit id="ID1">\n' +
' <notes>\n' +
' <note category="location">some-file.ts:281,286</note>\n' +
' <note category="location">some-other-file.ts:281</note>\n' +
' <note category="description">test description</note>\n' +
' </notes>\n' +
' <segment>\n' +
' <source>source val</source>\n' +
' </segment>\n' +
' </unit>\n' +
' </file>\n' +
'</xliff>',
options: {
format: 'xlf2'
},
messagesExpected: '<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="de">\n' +
' <file id="ngi18n" original="ng.template">\n' +
' <unit id="ID1">\n' +
' <segment>\n' +
' <source>source val</source>\n' +
' </segment>\n' +
' </unit>\n' +
' </file>\n' +
'</xliff>',
})

});
test('keep context in messages source file when includeContext=true and format=xlf', async () => {
await runTest({
Expand Down
6 changes: 5 additions & 1 deletion src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ async function extractI18nMergeBuilder(options: Options, context: BuilderContext
...unit,
source: mapper(unit.source),
target: unit.target !== undefined ? mapper(unit.target) : undefined,
locations: removeContextSource ? [] : unit.locations
locations: removeContextSource ? [] : unit.locations,
description: removeContextSource ? undefined : unit.description,
meaning: removeContextSource ? undefined : unit.meaning
}));
if (sort === 'idAsc') {
return updatedUnits.sort((a, b) => a.id.localeCompare(b.id));
Expand Down Expand Up @@ -155,6 +157,8 @@ async function extractI18nMergeBuilder(options: Options, context: BuilderContext
source: mapper(unit.source),
target: unit.target !== undefined ? mapper(unit.target) : undefined,
locations: options.includeContext === true ? unit.locations : [],
meaning: options.includeContext === true ? unit.meaning : undefined,
description: options.includeContext === true ? unit.description : undefined,
// reset to original state, if source was changed to target from sourceLangTarget:
state: idsOfUnitsWithSourceChangedToSourceLangTarget.has(unit.id) ? (translationTargetFile.units.find(u => u.id === unit.id)?.state ?? unit.state) : unit.state
}));
Expand Down

0 comments on commit 93f08b2

Please sign in to comment.