diff --git a/openerp/addons/base/tests/test_translate.py b/openerp/addons/base/tests/test_translate.py index f9ce5189e20..c3691563aef 100644 --- a/openerp/addons/base/tests/test_translate.py +++ b/openerp/addons/base/tests/test_translate.py @@ -67,6 +67,23 @@ class TranslationToolsTestCase(unittest.TestCase): self.assertItemsEqual(terms, ['Form stuff', 'Blah blah blah', 'Put some more text here']) + def test_translate_xml_inline3(self): + """ Test xml_translate() with formatting elements without actual text. """ + terms = [] + source = """
+
+ +

Blah blah blah

+ + + +
+ """ + result = xml_translate(terms.append, source) + self.assertEquals(result, source) + self.assertItemsEqual(terms, + ['Form stuff', 'Blah blah blah']) + def test_translate_xml_t(self): """ Test xml_translate() with t-* attributes. """ terms = [] diff --git a/openerp/tools/translate.py b/openerp/tools/translate.py index 1d6dbedaf93..b4e54b06537 100644 --- a/openerp/tools/translate.py +++ b/openerp/tools/translate.py @@ -181,9 +181,12 @@ class XMLTranslator(object): self.callback = callback # callback function to translate terms self._done = [] # translated strings self._todo = [] # todo strings that come after _done + self.needs_trans = False # whether todo needs translation - def todo(self, text): + def todo(self, text, needs_trans=True): self._todo.append(text) + if needs_trans and text.strip(): + self.needs_trans = True def all_todo(self): return not self._done @@ -194,8 +197,10 @@ class XMLTranslator(object): def flush(self): if self._todo: todo = "".join(self._todo) - self._done.append(self.process_text(todo)) + done = self.process_text(todo) if self.needs_trans else todo + self._done.append(done) del self._todo[:] + self.needs_trans = False def done(self, text): self.flush() @@ -231,7 +236,8 @@ class XMLTranslator(object): node.tag in TRANSLATED_ELEMENTS and not any(attr.startswith("t-") for attr in node.attrib)): # serialize the node element as todo - self.todo(serialize(node.tag, node.attrib, child_trans.get_todo())) + self.todo(serialize(node.tag, node.attrib, child_trans.get_todo()), + child_trans.needs_trans) else: # complete translations and serialize result as done for attr in TRANSLATED_ATTRS: