diff options
author | Claude Paroz <claude@2xlibre.net> | 2011-05-31 22:46:29 +0200 |
---|---|---|
committer | Shaun McCance <shaunm@gnome.org> | 2011-06-24 10:21:08 -0400 |
commit | 333218d4978a7b203252d35e7979f64cfb3b0c1c (patch) | |
tree | a326a5b2013b5317703bdd6deb2ad408f61b32c2 | |
parent | 7cda8e16e2281e0e6c42f1e47bfc98ee5e4fe4ae (diff) | |
download | itstool-333218d4978a7b203252d35e7979f64cfb3b0c1c.tar.gz |
Add itst drop rule
The itst Droprule is a rule allowing to ignore completely a tag from
the translation, including its content. The resulting xml will not
have the tag either.
-rwxr-xr-x | itstool.in | 7 | ||||
-rw-r--r-- | tests/Droprule.ll.po | 15 | ||||
-rw-r--r-- | tests/Droprule.ll.xml | 11 | ||||
-rw-r--r-- | tests/Droprule.pot | 15 | ||||
-rw-r--r-- | tests/Droprule.xml | 10 | ||||
-rw-r--r-- | tests/run_tests.py | 4 |
6 files changed, 61 insertions, 1 deletions
@@ -318,6 +318,7 @@ class Document (object): self._its_within_text_nodes = {} self._its_loc_notes = {} self._itst_preserve_space_nodes = {} + self._itst_drop_nodes = [] self._its_lang = {} self._itst_lang_attr = {} self._itst_credits = None @@ -338,6 +339,10 @@ class Document (object): if rule.prop('selector') is not None: for node in self._try_xpath_eval(xpath, rule.prop('selector')): self._itst_preserve_space_nodes[node] = rule.prop('preserveSpace') + elif xml_is_ns_name(rule, NS_ITST, 'dropRule'): + if rule.prop('selector') is not None: + for node in self._try_xpath_eval(xpath, rule.prop('selector')): + self._itst_drop_nodes.append(node) elif xml_is_ns_name(rule, NS_ITS, 'locNoteRule'): locnote = None for child in xml_child_iter(rule): @@ -689,7 +694,7 @@ class Document (object): if node.type in ('text', 'cdata') and msg is not None: msg.add_text(node.content) return - if node.type != 'element': + if node.type != 'element' or node in self._itst_drop_nodes: return translate = self.get_its_translate(node) if translate is None: diff --git a/tests/Droprule.ll.po b/tests/Droprule.ll.po new file mode 100644 index 0000000..eb41397 --- /dev/null +++ b/tests/Droprule.ll.po @@ -0,0 +1,15 @@ +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: 2011-06-01 22:50+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/Droprule.xml:8(content/p) +msgid "Everything started now." +msgstr "Tout commença à l'instant." + diff --git a/tests/Droprule.ll.xml b/tests/Droprule.ll.xml new file mode 100644 index 0000000..9eef088 --- /dev/null +++ b/tests/Droprule.ll.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8"?> +<doc xmlns:its="http://www.w3.org/2005/11/its" xmlns:itst="http://itstool.org/extensions/" its:version="1.0"> + <head> + <its:rules version="1.0"> + <itst:dropRule selector="//blanktag"/> + </its:rules> + </head> + <content> + <p>Tout commença à l'instant.</p> + </content> +</doc> diff --git a/tests/Droprule.pot b/tests/Droprule.pot new file mode 100644 index 0000000..e490476 --- /dev/null +++ b/tests/Droprule.pot @@ -0,0 +1,15 @@ +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: 2011-06-01 22:50+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/Droprule.xml:8(content/p) +msgid "Everything started now." +msgstr "" + diff --git a/tests/Droprule.xml b/tests/Droprule.xml new file mode 100644 index 0000000..39a05ea --- /dev/null +++ b/tests/Droprule.xml @@ -0,0 +1,10 @@ +<doc xmlns:its="http://www.w3.org/2005/11/its" xmlns:itst="http://itstool.org/extensions/" its:version="1.0"> + <head> + <its:rules version="1.0"> + <itst:dropRule selector="//blanktag"/> + </its:rules> + </head> + <content> + <p><blanktag/>Everything started now.</p> + </content> +</doc> diff --git a/tests/run_tests.py b/tests/run_tests.py index 8b35d0b..08a9aa1 100644 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -110,6 +110,10 @@ class ItstoolTests(unittest.TestCase): def test_withintext_linkedrules(self): self._test_translation_process('WithinText2.xml') + # **** custom itst rules **** + def test_droprule(self): + self._test_translation_process('Droprule.xml') + def test_attributes1(self): self._test_translation_process('Attributes1.xml') |