diff --git a/odoo/addons/test_translation_import/__manifest__.py b/odoo/addons/test_translation_import/__manifest__.py index bc20d0da61d..5f7ff9a4427 100644 --- a/odoo/addons/test_translation_import/__manifest__.py +++ b/odoo/addons/test_translation_import/__manifest__.py @@ -11,4 +11,7 @@ ], 'installable': True, 'auto_install': False, + 'qweb': [ + 'static/src/xml/js_templates.xml', + ] } diff --git a/odoo/addons/test_translation_import/static/src/xml/js_templates.xml b/odoo/addons/test_translation_import/static/src/xml/js_templates.xml new file mode 100644 index 00000000000..6744603c510 --- /dev/null +++ b/odoo/addons/test_translation_import/static/src/xml/js_templates.xml @@ -0,0 +1,13 @@ + + diff --git a/odoo/addons/test_translation_import/tests/test_term_count.py b/odoo/addons/test_translation_import/tests/test_term_count.py index 4e6c9de0a52..9815e95a260 100644 --- a/odoo/addons/test_translation_import/tests/test_term_count.py +++ b/odoo/addons/test_translation_import/tests/test_term_count.py @@ -7,7 +7,7 @@ import io import odoo from odoo.tests import common, tagged from odoo.tools.misc import file_open, mute_logger -from odoo.tools.translate import _, _lt, TranslationFileReader +from odoo.tools.translate import _, _lt, TranslationFileReader, TranslationModuleReader TRANSLATED_TERM = _lt("Klingon") @@ -319,3 +319,17 @@ class TestTranslationFlow(common.TransactionCase): ]) self.assertEqual(init_translation_count, len(import_translation)) + + def test_export_static_templates(self): + trans_static = [] + po_reader = TranslationModuleReader(self.env.cr, ['test_translation_import']) + for line in po_reader: + module, ttype, name, res_id, source, value, comments = line + if name == "addons/test_translation_import/static/src/xml/js_templates.xml": + trans_static.append(source) + + self.assertNotIn('no export', trans_static) + self.assertIn('do export', trans_static) + self.assertIn('text node', trans_static) + self.assertIn('slot', trans_static) + self.assertIn('slot 2', trans_static) diff --git a/odoo/tools/translate.py b/odoo/tools/translate.py index 038b1431940..ed3b3e66bd1 100644 --- a/odoo/tools/translate.py +++ b/odoo/tools/translate.py @@ -842,10 +842,20 @@ def _extract_translatable_qweb_terms(element, callback): and "t-js" not in el.attrib and not ("t-jquery" in el.attrib and "t-operation" not in el.attrib) and el.get("t-translation", '').strip() != "off"): + _push(callback, el.text, el.sourceline) - for att in ('title', 'alt', 'label', 'placeholder', 'aria-label'): - if att in el.attrib: - _push(callback, el.attrib[att], el.sourceline) + # Do not export terms contained on the Component directive of OWL + # attributes in this context are most of the time variables, + # not real HTML attributes. + # Node tags starting with a capital letter are considered OWL Components + # and a widespread convention and good practice for DOM tags is to write + # them all lower case. + # https://www.w3schools.com/html/html5_syntax.asp + # https://github.com/odoo/owl/blob/master/doc/reference/component.md#composition + if not el.tag[0].isupper() and 't-component' not in el.attrib: + for att in ('title', 'alt', 'label', 'placeholder', 'aria-label'): + if att in el.attrib: + _push(callback, el.attrib[att], el.sourceline) _extract_translatable_qweb_terms(el, callback) _push(callback, el.tail, el.sourceline)