[FIX] tools: properly verify the size of HTML nodes
Instead of checking the size of text only node, let the xml_translate verify it. The size verification using etree was introduced at40efdccc3dbut was probably too simple. Since45352512a8, this becomes redundant with the nonspace method which can be extended. The re.sub is still relevant as some terms may contain only non-alphanumeric and use push_translation (e.g. '>=' as a selection or xml terms extracted by babel in static repository) closes odoo/odoo#29432
This commit is contained in:
@@ -159,7 +159,7 @@ def translate_xml_node(node, callback, parse, serialize):
|
||||
"""
|
||||
|
||||
def nonspace(text):
|
||||
return bool(text) and not text.isspace()
|
||||
return bool(text) and len(re.sub(r'\W+', '', text)) > 1
|
||||
|
||||
def concat(text1, text2):
|
||||
return text2 if text1 is None else text1 + (text2 or "")
|
||||
@@ -810,14 +810,6 @@ def trans_generate(lang, modules, cr):
|
||||
# empty and one-letter terms are ignored, they probably are not meant to be
|
||||
# translated, and would be very hard to translate anyway.
|
||||
sanitized_term = (source or '').strip()
|
||||
try:
|
||||
# verify the minimal size without eventual xml tags
|
||||
# wrap to make sure html content like '<a>b</a><c>d</c>' is accepted by lxml
|
||||
wrapped = u"<div>%s</div>" % sanitized_term
|
||||
node = etree.fromstring(wrapped)
|
||||
sanitized_term = etree.tostring(node, encoding='unicode', method='text')
|
||||
except etree.ParseError:
|
||||
pass
|
||||
# remove non-alphanumeric chars
|
||||
sanitized_term = re.sub(r'\W+', '', sanitized_term)
|
||||
if not sanitized_term or len(sanitized_term) <= 1:
|
||||
|
||||
Reference in New Issue
Block a user