diff options
-rwxr-xr-x | itstool.in | 12 | ||||
-rw-r--r-- | tests/Placeholder.ll.po | 19 | ||||
-rw-r--r-- | tests/Placeholder.ll.xml | 6 | ||||
-rw-r--r-- | tests/Placeholder.xml | 5 | ||||
-rw-r--r-- | tests/run_tests.py | 4 |
5 files changed, 43 insertions, 3 deletions
@@ -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 <EMAIL@ADDRESS>\n" +"Language-Team: LANGUAGE <LL@li.org>\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 @@ +<?xml version="1.0" encoding="utf-8"?> +<book xmlns:its="http://www.w3.org/2005/11/its" its:version="1.0" lang="test"> + <body> + <p>Voici le premier paragraphe. Il contient une note liée à son dernier mot<note><p>Voici une note.</p></note>.</p> + </body> +</book> 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 @@ +<book xmlns:its="http://www.w3.org/2005/11/its" its:version="1.0"> + <body> + <p>This is the first paragraph. It has a note on its final word<note><p>This is a note.</p></note>.</p> + </body> +</book> 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): |