From 40efdccc3d1e1f070c9d9588b2220c8e38d6432f Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Tue, 25 Aug 2015 14:59:33 +0200 Subject: [PATCH] [IMP] tools: skip small html elements Small one letter terms are ignored when pushing the translations. If these are included inside xml tags (e.g. #1, the term should also be ignored. Strip xml eventual tags when checking the length of a term. --- openerp/tools/translate.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/openerp/tools/translate.py b/openerp/tools/translate.py index fbd76e59c14..72c2190fee3 100644 --- a/openerp/tools/translate.py +++ b/openerp/tools/translate.py @@ -767,7 +767,18 @@ def trans_generate(lang, modules, cr): def push_translation(module, type, name, id, source, comments=None): # empty and one-letter terms are ignored, they probably are not meant to be # translated, and would be very hard to translate anyway. - if not source or len(source.strip()) <= 1: + sanitized_term = (source or '').strip() + try: + # verify the minimal size without eventual xml tags + # wrap to make sure html content like 'bd' is accepted by lxml + wrapped = "
%s
" % sanitized_term + node = etree.fromstring(wrapped) + sanitized_term = etree.tostring(node, encoding='UTF-8', 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: return tnx = (module, source, name, id, type, tuple(comments or ()))