From 6411b09431eb72ed5426d40a0142e7479c486d3b Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Wed, 29 Jun 2011 21:15:46 +0200 Subject: Fix placeholder translation when it contains sub-elements --- itstool.in | 12 ++++++++++-- tests/Placeholder.ll.po | 19 +++++++++++++++++++ tests/Placeholder.ll.xml | 6 ++++++ tests/Placeholder.xml | 5 +++++ tests/run_tests.py | 4 +++- 5 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 tests/Placeholder.ll.po create mode 100644 tests/Placeholder.ll.xml create mode 100644 tests/Placeholder.xml diff --git a/itstool.in b/itstool.in index 2401918..1db369c 100755 --- a/itstool.in +++ b/itstool.in @@ -692,8 +692,13 @@ class Document (object): if child.type != 'element': continue if child.ns() is not None and child.ns().content == NS_BLANK: - repl = self.get_translated(msg.get_placeholder(child.name).node, translations) - child.replaceNode(repl) + ph_node = msg.get_placeholder(child.name).node + if self.has_child_elements(ph_node): + self.merge_translations(translations, None, ph_node) + child.replaceNode(ph_node) + else: + repl = self.get_translated(ph_node, translations) + child.replaceNode(repl) scan_node(child) scan_node(trnode) retnode = node.copyNode(2) @@ -802,6 +807,9 @@ class Document (object): def is_translation_unit (self, node): return self.get_its_within_text(node) != 'yes' + def has_child_elements(self, node): + return len([child for child in xml_child_iter(node) if child.type=='element']) + def get_preserve_space (self, node): if node.getSpacePreserve() == 1: return True diff --git a/tests/Placeholder.ll.po b/tests/Placeholder.ll.po new file mode 100644 index 0000000..43190bf --- /dev/null +++ b/tests/Placeholder.ll.po @@ -0,0 +1,19 @@ +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: 2011-06-29 21:02+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: tests/Placeholder.xml:3(note/p) +msgid "This is a note." +msgstr "Voici une note." + +#: tests/Placeholder.xml:3(body/p) +msgid "This is the first paragraph. It has a note on its final word<_:note-1/>." +msgstr "Voici le premier paragraphe. Il contient une note liée à son dernier mot<_:note-1/>." + diff --git a/tests/Placeholder.ll.xml b/tests/Placeholder.ll.xml new file mode 100644 index 0000000..986cd19 --- /dev/null +++ b/tests/Placeholder.ll.xml @@ -0,0 +1,6 @@ + + + +

Voici le premier paragraphe. Il contient une note liée à son dernier mot

Voici une note.

.

+ +
diff --git a/tests/Placeholder.xml b/tests/Placeholder.xml new file mode 100644 index 0000000..d03fb77 --- /dev/null +++ b/tests/Placeholder.xml @@ -0,0 +1,5 @@ + + +

This is the first paragraph. It has a note on its final word

This is a note.

.

+ +
diff --git a/tests/run_tests.py b/tests/run_tests.py index e8b009e..9f0ca9a 100644 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -18,7 +18,7 @@ class ItstoolTests(unittest.TestCase): """ Helper method to run a shell command """ # Set stdout = sys.stdout to debug a subprocess if you set a breakpoint in it pipe = Popen(cmd, shell=True, env=os.environ, stdin=None, stdout=PIPE, stderr=PIPE) - (output, errout) = map(lambda x:x.decode(), pipe.communicate()) + (output, errout) = map(lambda x:x.decode('utf-8'), pipe.communicate()) status = pipe.returncode self.assertEqual(status, 0, errout or output) return (status, output, errout) @@ -120,6 +120,8 @@ class ItstoolTests(unittest.TestCase): def test_context(self): self._test_translation_process('Context.xml') + def test_deep_placeholder(self): + self._test_translation_process('Placeholder.xml') class ITSTestRunner(unittest.TextTestRunner): def run(self, test): -- cgit v1.2.1