diff options
| author | Martin Trigaux <mat@odoo.com> | 2015-08-25 14:59:33 +0200 |
|---|---|---|
| committer | Martin Trigaux <mat@odoo.com> | 2015-08-26 16:11:51 +0200 |
| commit | 40efdccc3d1e1f070c9d9588b2220c8e38d6432f (patch) | |
| tree | e3fcbdf9ab6e09ce70a682d948e1914adf99585d | |
| parent | b322536aa622dbcac3aa8750c4a51eaaec21001f (diff) | |
[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. <strong>#1</strong>, the term should
also be ignored.
Strip xml eventual tags when checking the length of a term.
| -rw-r--r-- | openerp/tools/translate.py | 13 |
1 files changed, 12 insertions, 1 deletions
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 '<a>b</a><c>d</c>' is accepted by lxml + wrapped = "<div>%s</div>" % 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 ())) |
