summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Bouvy <dbo@odoo.com>2015-02-04 17:23:50 +0100
committerDamien Bouvy <dbo@odoo.com>2015-02-06 15:48:28 +0100
commitcc71a41e8be81a59dca39feb3fb45f182ec0bb61 (patch)
tree307b190f3bec0848d47b8a2ebc4fcbcc6604df9f
parent0fc3ca389775ae74166f523d1d2069a3a0a287d7 (diff)
[IMP] qweb: t-call tags have an optionnal t-lang attribute to make translations easier
-rw-r--r--openerp/addons/base/ir/ir_qweb.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/openerp/addons/base/ir/ir_qweb.py b/openerp/addons/base/ir/ir_qweb.py
index 9fb86044493..103c60c8fa1 100644
--- a/openerp/addons/base/ir/ir_qweb.py
+++ b/openerp/addons/base/ir/ir_qweb.py
@@ -432,6 +432,14 @@ class QWeb(orm.AbstractModel):
def render_tag_call(self, element, template_attributes, generated_attributes, qwebcontext):
d = qwebcontext.copy()
+
+ if 'lang' in template_attributes:
+ init_lang = d.context.get('lang', 'en_US')
+ lang = template_attributes['lang']
+ d.context['lang'] = self.eval(lang, d) or lang
+ if not self.pool['res.lang'].search(d.cr, d.uid, [('code', '=', lang)], count=True, context=d.context):
+ _logger.info("'%s' is not a valid language code, is an empty field or is not installed, falling back to en_US", lang)
+
d[0] = self.render_element(element, template_attributes, generated_attributes, d)
cr = d.get('request') and d['request'].cr or None
uid = d.get('request') and d['request'].uid or None
@@ -441,7 +449,14 @@ class QWeb(orm.AbstractModel):
template = int(template)
except ValueError:
pass
- return self.render(cr, uid, template, d)
+
+ res = self.render(cr, uid, template, d)
+
+ # we need to reset the lang after the rendering
+ if 'lang' in template_attributes:
+ d.context['lang'] = init_lang
+
+ return res
def render_tag_call_assets(self, element, template_attributes, generated_attributes, qwebcontext):
""" This special 't-call' tag can be used in order to aggregate/minify javascript and css assets"""