From 3caafac8c02c773aa6ae1243e03edd64c2ad081b Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Tue, 16 Sep 2014 17:02:05 +0200 Subject: [PATCH] [FIX] ir.ui.view: match translated terms without heading/trailing whitespace As the whitespace is stripped when exporting terms to translate, it must be done as well when matching translations at runtime. Fixes issue #1755 partly --- openerp/addons/base/ir/ir_ui_view.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/openerp/addons/base/ir/ir_ui_view.py b/openerp/addons/base/ir/ir_ui_view.py index 3302ec065bb..ce6f2b4e020 100644 --- a/openerp/addons/base/ir/ir_ui_view.py +++ b/openerp/addons/base/ir/ir_ui_view.py @@ -685,27 +685,30 @@ class view(osv.osv): if 'lang' in context: Translations = self.pool['ir.translation'] if node.text and node.text.strip(): - trans = Translations._get_source(cr, user, model, 'view', context['lang'], node.text.strip()) + term = node.text.strip() + trans = Translations._get_source(cr, user, model, 'view', context['lang'], term) if trans: - node.text = node.text.replace(node.text.strip(), trans) + node.text = node.text.replace(term, trans) if node.tail and node.tail.strip(): - trans = Translations._get_source(cr, user, model, 'view', context['lang'], node.tail.strip()) + term = node.tail.strip() + trans = Translations._get_source(cr, user, model, 'view', context['lang'], term) if trans: - node.tail = node.tail.replace(node.tail.strip(), trans) + node.tail = node.tail.replace(term, trans) - if node.get('string') and not result: - trans = Translations._get_source(cr, user, model, 'view', context['lang'], node.get('string')) - if trans == node.get('string') and ('base_model_name' in context): + if node.get('string') and node.get('string').strip() and not result: + term = node.get('string').strip() + trans = Translations._get_source(cr, user, model, 'view', context['lang'], term) + if trans == term and ('base_model_name' in context): # If translation is same as source, perhaps we'd have more luck with the alternative model name # (in case we are in a mixed situation, such as an inherited view where parent_view.model != model - trans = Translations._get_source(cr, user, context['base_model_name'], 'view', context['lang'], node.get('string')) + trans = Translations._get_source(cr, user, context['base_model_name'], 'view', context['lang'], term) if trans: node.set('string', trans) for attr_name in ('confirm', 'sum', 'avg', 'help', 'placeholder'): attr_value = node.get(attr_name) - if attr_value: - trans = Translations._get_source(cr, user, model, 'view', context['lang'], attr_value) + if attr_value and attr_value.strip(): + trans = Translations._get_source(cr, user, model, 'view', context['lang'], attr_value.strip()) if trans: node.set(attr_name, trans)