From cd4080839f501ad01bda59c8ead1184fb3cdd48e Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Tue, 11 Dec 2018 13:50:27 +0000 Subject: [PATCH] [FIX] translate: inline elements with translatable attributes only --- odoo/addons/base/tests/test_translate.py | 14 ++++++++++++++ odoo/tools/translate.py | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/tests/test_translate.py b/odoo/addons/base/tests/test_translate.py index 76ff73aeebe..0d9ce07bb20 100644 --- a/odoo/addons/base/tests/test_translate.py +++ b/odoo/addons/base/tests/test_translate.py @@ -114,6 +114,20 @@ class TranslationToolsTestCase(unittest.TestCase): self.assertItemsEqual(terms, ['Form stuff', 'Blah blah blah']) + def test_translate_xml_inline4(self): + """ Test xml_translate() with inline elements with translated attrs only. """ + terms = [] + source = """
+
+
+
""" + result = xml_translate(terms.append, source) + self.assertEquals(result, source) + self.assertItemsEqual(terms, + ['Form stuff', '']) + def test_translate_xml_t(self): """ Test xml_translate() with t-* attributes. """ terms = [] diff --git a/odoo/tools/translate.py b/odoo/tools/translate.py index 08cffbb78be..3c031f3d277 100644 --- a/odoo/tools/translate.py +++ b/odoo/tools/translate.py @@ -251,7 +251,10 @@ def translate_xml_node(node, callback, parse, serialize): # complete result and return it append_content(result, todo) result.tail = node.tail - has_text = todo_has_text or nonspace(result.text) or nonspace(result.tail) + has_text = ( + todo_has_text or nonspace(result.text) or nonspace(result.tail) + or any(name in TRANSLATED_ATTRS for name in result.attrib) + ) return (has_text, result) # translate the content of todo and append it to result