diff --git a/openerp/addons/base/tests/test_translate.py b/openerp/addons/base/tests/test_translate.py index c3691563aef..ce3e7fd51ae 100644 --- a/openerp/addons/base/tests/test_translate.py +++ b/openerp/addons/base/tests/test_translate.py @@ -96,3 +96,28 @@ class TranslationToolsTestCase(unittest.TestCase): self.assertEquals(result, source) self.assertItemsEqual(terms, ['stuff before', 'stuff after']) + + def test_translate_xml_off(self): + """ Test xml_translate() with attribute translate="off". """ + terms = [] + source = """
+ stuff before +
Do not translate this
+ stuff after +
""" + result = xml_translate(terms.append, source) + self.assertEquals(result, source) + self.assertItemsEqual(terms, + ['stuff before', 'stuff after']) + + def test_translate_xml_attribute(self): + """ Test xml_translate() with elements. """ + terms = [] + source = """ + Translate this + Do not translate this + """ + result = xml_translate(terms.append, source) + self.assertEquals(result, source) + self.assertItemsEqual(terms, + ['Translate this']) diff --git a/openerp/tools/translate.py b/openerp/tools/translate.py index b4e54b06537..2c2bdaffab2 100644 --- a/openerp/tools/translate.py +++ b/openerp/tools/translate.py @@ -219,8 +219,13 @@ class XMLTranslator(object): def process(self, node): """ Process the given xml `node`: collect `todo` and `done` items. """ - if isinstance(node, SKIPPED_ELEMENT_TYPES) or node.tag in SKIPPED_ELEMENTS: - # serialize the node as done, but keep its tail as todo + if ( + isinstance(node, SKIPPED_ELEMENT_TYPES) or + node.tag in SKIPPED_ELEMENTS or + node.get("translation", "").strip() == "off" or + node.tag == "attribute" and node.get("name") not in TRANSLATED_ATTRS + ): + # do not translate the contents of the node tail, node.tail = node.tail, None self.done(etree.tostring(node)) self.todo(escape(tail or ""))