Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure jsToXliff functions generate valid xliff files #58

Merged
merged 3 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/js2xliff.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function createGroupUnitTag (id, group) {
function createUnitTag (id, unit) {
const segment = makeElement('segment', null, true)
if (!unit.source && unit.target) unit.source = ''
if (unit.source) segment.elements.push(makeElement('source', null, makeValue(unit.source, ElementTypes2)))
if (unit.source !== undefined) segment.elements.push(makeElement('source', null, makeValue(unit.source, ElementTypes2)))
if (unit.target !== undefined) segment.elements.push(makeElement('target', null, makeValue(unit.target, ElementTypes2)))
const subEle = [segment]
if ('note' in unit) {
Expand Down
2 changes: 1 addition & 1 deletion lib/jsToXliff12.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function createTransUnitTag (key, resource, obj, options) {
}
}
if (!resource.source && resource.target) resource.source = ''
if (resource.source) u.elements.push(makeElement('source', sourceAttributes, makeValue(resource.source, ElementTypes12)))
if (resource.source != null) u.elements.push(makeElement('source', sourceAttributes, makeValue(resource.source, ElementTypes12)))
if (resource.target != null) {
let targetAttributes = null
if (options.xmlLangAttr && obj.targetLanguage) {
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"to ' \"esc<ap> & e": {
"source": "special chars",
"target": "spezielle Charakter"
},
"keyWithEmptySource": {
"source": "",
"target": "Anything"
}
}
},
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/example.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@
<target>spezielle Charakter</target>
</segment>
</unit>
<unit id="keyWithEmptySource">
<segment>
<source></source>
<target>Anything</target>
</segment>
</unit>
</file>
</xliff>
4 changes: 4 additions & 0 deletions test/fixtures/example12.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
<source>special chars</source>
<target>spezielle Charakter</target>
</trans-unit>
<trans-unit id="keyWithEmptySource">
<source></source>
<target>Anything</target>
</trans-unit>
</body>
</file>
</xliff>
4 changes: 4 additions & 0 deletions test/fixtures/example12_diff.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@
<target>other (AR)</target>
</trans-unit>
<trans-unit id="key2_zero">
<source></source>
<target>zero (AR)</target>
</trans-unit>
<trans-unit id="key2_two">
<source></source>
<target>two (AR)</target>
</trans-unit>
<trans-unit id="key2_few">
<source></source>
<target>few (AR)</target>
</trans-unit>
<trans-unit id="key2_many">
<source></source>
<target>many (AR)</target>
</trans-unit>
</body>
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/example12_output_note.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<target>spezielle Charakter</target>
<note>special chars note</note>
</trans-unit>
<trans-unit id="keyWithEmptySource">
<source></source>
<target>Anything</target>
</trans-unit>
</body>
</file>
</xliff>
2 changes: 1 addition & 1 deletion test/fixtures/example_compact.xliff
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="en-US" trgLang="de-CH"><file id="namespace1"><unit id="key1"><segment><source>Hello</source><target>Hallo</target></segment></unit><unit id="key2"><segment><source>An application to manipulate and process XLIFF documents</source><target>Eine Applikation um XLIFF Dokumente zu manipulieren und verarbeiten</target></segment></unit><unit id="key.nested"><segment><source>XLIFF Data Manager</source><target>XLIFF Daten Manager</target></segment></unit><unit id="to &apos; &quot;esc&lt;ap&gt; &amp; e"><segment><source>special chars</source><target>spezielle Charakter</target></segment></unit></file></xliff>
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="en-US" trgLang="de-CH"><file id="namespace1"><unit id="key1"><segment><source>Hello</source><target>Hallo</target></segment></unit><unit id="key2"><segment><source>An application to manipulate and process XLIFF documents</source><target>Eine Applikation um XLIFF Dokumente zu manipulieren und verarbeiten</target></segment></unit><unit id="key.nested"><segment><source>XLIFF Data Manager</source><target>XLIFF Daten Manager</target></segment></unit><unit id="to &apos; &quot;esc&lt;ap&gt; &amp; e"><segment><source>special chars</source><target>spezielle Charakter</target></segment></unit><unit id="keyWithEmptySource"><segment><source></source><target>Anything</target></segment></unit></file></xliff>
2 changes: 1 addition & 1 deletion test/fixtures/example_compact12.xliff
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<xliff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd" xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"><file original="namespace1" datatype="plaintext" source-language="en-US" target-language="de-CH"><body><trans-unit id="key1"><source>Hello</source><target>Hallo</target></trans-unit><trans-unit id="key2"><source>An application to manipulate and process XLIFF documents</source><target>Eine Applikation um XLIFF Dokumente zu manipulieren und verarbeiten</target></trans-unit><trans-unit id="key.nested"><source>XLIFF Data Manager</source><target>XLIFF Daten Manager</target></trans-unit><trans-unit id="to &apos; &quot;esc&lt;ap&gt; &amp; e"><source>special chars</source><target>spezielle Charakter</target></trans-unit></body></file></xliff>
<xliff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd" xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"><file original="namespace1" datatype="plaintext" source-language="en-US" target-language="de-CH"><body><trans-unit id="key1"><source>Hello</source><target>Hallo</target></trans-unit><trans-unit id="key2"><source>An application to manipulate and process XLIFF documents</source><target>Eine Applikation um XLIFF Dokumente zu manipulieren und verarbeiten</target></trans-unit><trans-unit id="key.nested"><source>XLIFF Data Manager</source><target>XLIFF Daten Manager</target></trans-unit><trans-unit id="to &apos; &quot;esc&lt;ap&gt; &amp; e"><source>special chars</source><target>spezielle Charakter</target></trans-unit><trans-unit id="keyWithEmptySource"><source></source><target>Anything</target></trans-unit></body></file></xliff>
4 changes: 4 additions & 0 deletions test/fixtures/example_diff.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@
"target": "other (AR)"
},
"key2_zero": {
"source": "",
"target": "zero (AR)"
},
"key2_two": {
"source": "",
"target": "two (AR)"
},
"key2_few": {
"source": "",
"target": "few (AR)"
},
"key2_many": {
"source": "",
"target": "many (AR)"
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/example_diff.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,25 @@
</unit>
<unit id="key2_zero">
<segment>
<source></source>
<target>zero (AR)</target>
</segment>
</unit>
<unit id="key2_two">
<segment>
<source></source>
<target>two (AR)</target>
</segment>
</unit>
<unit id="key2_few">
<segment>
<source></source>
<target>few (AR)</target>
</segment>
</unit>
<unit id="key2_many">
<segment>
<source></source>
<target>many (AR)</target>
</segment>
</unit>
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/example_output_note.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"note": "special chars note",
"source": "special chars",
"target": "spezielle Charakter"
},
"keyWithEmptySource": {
"source": "",
"target": "Anything"
}
}
},
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/example_output_note.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@
<target>spezielle Charakter</target>
</segment>
</unit>
<unit id="keyWithEmptySource">
<segment>
<source></source>
<target>Anything</target>
</segment>
</unit>
</file>
</xliff>
3 changes: 2 additions & 1 deletion test/fixtures/example_source.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"key1": "Hello",
"key2": "An application to manipulate and process XLIFF documents",
"key.nested": "XLIFF Data Manager",
"to ' \"esc<ap> & e": "special chars"
"to ' \"esc<ap> & e": "special chars",
"keyWithEmptySource": ""
}
4 changes: 4 additions & 0 deletions test/fixtures/example_source_attr12.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
<source xml:lang="en-US">special chars</source>
<target xml:lang="de-CH">spezielle Charakter</target>
</trans-unit>
<trans-unit id="keyWithEmptySource">
<source xml:lang="en-US"></source>
<target xml:lang="de-CH">Anything</target>
</trans-unit>
</body>
</file>
</xliff>
3 changes: 2 additions & 1 deletion test/fixtures/example_target.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"key1": "Hallo",
"key2": "Eine Applikation um XLIFF Dokumente zu manipulieren und verarbeiten",
"key.nested": "XLIFF Daten Manager",
"to ' \"esc<ap> & e": "spezielle Charakter"
"to ' \"esc<ap> & e": "spezielle Charakter",
"keyWithEmptySource": "Anything"
}
Loading