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

fix: handle id with escaped characters - fixes #121 #122

Merged
merged 1 commit into from
Nov 27, 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
18 changes: 17 additions & 1 deletion src/model/translationFileSerialization.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,23 @@ describe('translationFileSerialization', () => {
</file>
</xliff>`);
});
it('should output additinalAttribute', () => {
it('should output id with quotes', () => {
const input = new TranslationFile([{
id: 'idWithQuote"',
source: 'some source',
locations: []
}], 'en', 'de', '');
expect(toXlf1(input, {prettyNestedTags: true})).toEqual(`<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" target-language="de" datatype="plaintext" original="ng2.template">
<body>
<trans-unit id="idWithQuote&quot;" datatype="html">
<source>some source</source>
</trans-unit>
</body>
</file>
</xliff>`);
});
it('should output additionalAttribute', () => {
const input = new TranslationFile([{
id: 'ID1',
source: 'source val',
Expand Down
6 changes: 4 additions & 2 deletions src/model/translationFileSerialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ export function toXlf2(translationFile: TranslationFile, options: Pick<Options,
}
const file = doc.childNamed('file')!;
file.children = translationFile.units.map(unit => {
const u = new XmlDocument(`<unit id="${unit.id}"><segment><source>${unit.source}</source></segment></unit>`);
const u = new XmlDocument(`<unit id=""><segment><source>${unit.source}</source></segment></unit>`);
u.attr.id = unit.id;
const segment = u.childNamed('segment')!;
if (unit.target !== undefined) {
segment.children.push(new XmlDocument(`<target>${unit.target}</target>`));
Expand Down Expand Up @@ -171,9 +172,10 @@ export function toXlf1(translationFile: TranslationFile, options: Pick<Options,
}
const body = file.childNamed('body')!;
body.children = translationFile.units.map(unit => {
const transUnit = new XmlDocument(`<trans-unit id="${unit.id}" datatype="html">
const transUnit = new XmlDocument(`<trans-unit id="" datatype="html">
<source>${unit.source}</source>
</trans-unit>`);
transUnit.attr.id = unit.id;
if (unit.target !== undefined) {
const target = new XmlDocument(`<target>${unit.target}</target>`);
if (unit.state !== undefined) {
Expand Down
Loading