summaryrefslogtreecommitdiff
path: root/odoo/tools
diff options
context:
space:
mode:
authorLucas Perais (lpe) <lpe@odoo.com>2020-02-24 16:28:08 +0000
committerLucas Perais (lpe) <lpe@odoo.com>2020-04-17 12:55:32 +0000
commit69b51ce05e855b2b95e75919ac97996a1ff5e136 (patch)
treeadfc4fbc37f0b696eef46c75cf1d2a161c07ad0b /odoo/tools
parentbf97152ce99f84a524ed8773280b4bba8fca38da (diff)
[FIX] translate: do not export OWL directive's attribute
Have a static template of the form: ```xml <div t-name="ComponentA"> <ComponentB title="no export" /> </div> ``` To be used by OWL (github.com/odoo/owl) In this context, the title in the attributes of ComponentB should not be considered as *the* title attribute of HTML but as a sort of variable declaration Before this commit, the string contained in the value of this title attribute was exported. It was not translated at runtime, but we want to export as less stuff as possible in PO files So, after this commit, none of the attributes held by a OWL directive are exported This commit relies on OWL Syntax, which makes mandatory for a component directive's first letter to be capitalized https://github.com/odoo/owl/blob/master/doc/reference/component.md#composition Also, it relies on the good practice and widespread convention to have every HTML node lower cased https://www.w3schools.com/html/html5_syntax.asp closes odoo/odoo#46191 Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
Diffstat (limited to 'odoo/tools')
-rw-r--r--odoo/tools/translate.py16
1 files changed, 13 insertions, 3 deletions
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)