Skip to content

Commit

Permalink
[localize] Fix XLIFF serialization regression (#3576)
Browse files Browse the repository at this point in the history
Fixes a bug introduced in #3514 where we were not correctly updating XLIFF messages that contained placeholders, because of an index-invalidation bug in the way we were deleting the contents of existing nodes.

Fixes #3569
  • Loading branch information
aomarks committed Jan 17, 2023
1 parent 8c42df4 commit 6be3073
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-readers-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lit/localize-tools': patch
---

Fix regression in Localize XLIFF serialization. When updating an existing XLIFF file, placeholders would appear in the wrong places.
4 changes: 3 additions & 1 deletion packages/localize-tools/src/formatters/xliff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,9 @@ export class XliffFormatter implements Formatter {
*/
private clearElement(element: Element) {
const children = element.childNodes;
for (let i = 0; i < children.length; i++) {
// Iterate backwards so we don't have to worry about the index changing each
// time we remove.
for (let i = children.length - 1; i >= 0; i--) {
element.removeChild(children.item(i));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

import {msg} from '@lit/localize';
import {msg, str} from '@lit/localize';

msg('I am translated', {desc: 'Description of translated'});
const who = 'World';
msg(str`I am translated. Hello ${who}.`, {desc: 'Description of translated'});
msg('I am not translated', {desc: 'Description of not translated'});
msg('I am translated with a note', {desc: 'Happy note'});
msg('My note needs to be migrated', {desc: 'Existing note'});
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<!-- Comment by translation tool -->
<file target-language="es-419" source-language="en" original="other-original" datatype="plaintext" date="2002-01-25T21:06:00Z">
<body>
<trans-unit id="s677cb50a446c46f4" approved="yes">
<source>I am translated</source>
<target state="translated">Estoy traducido</target>
<trans-unit id="sa6552c557bbace72" approved="yes">
<source>I am translated. Hello <ph id="0">${who}</ph>.</source>
<target state="translated">Estoy traducido. Hola <ph id="0">${who}</ph>.</target>
<note from="lit-localize">Description of translated</note>
</trans-unit>
<trans-unit id="s18fa8e4d6470399d">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

import {msg} from '@lit/localize';
import {msg, str} from '@lit/localize';

msg('I am translated', {desc: 'Description of translated'});
const who = 'World';
msg(str`I am translated. Hello ${who}.`, {desc: 'Description of translated'});
msg('I am not translated', {desc: 'Description of not translated'});
msg('I am translated with a note', {desc: 'Happy note'});
msg('My note needs to be migrated', {desc: 'Existing note'});
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<!-- Comment by translation tool -->
<file target-language="es-419" source-language="en" original="other-original" datatype="plaintext" date="2002-01-25T21:06:00Z">
<body>
<trans-unit id="s677cb50a446c46f4" approved="yes">
<source>I was translated</source>
<target state="translated">Estoy traducido</target>
<trans-unit id="sa6552c557bbace72" approved="yes">
<source>I was translated. Hello <ph id="0">${who}</ph>.</source>
<target state="translated">Estoy traducido. Hola <ph id="0">${who}</ph>.</target>
</trans-unit>
<trans-unit id="s18fa8e4d6470399d">
<source foo:attribute="bar">I am translated with a note</source>
Expand Down

0 comments on commit 6be3073

Please sign in to comment.