[IMP] qweb: t-call tags have an optionnal t-lang attribute to make translations easier

This commit is contained in:
Damien Bouvy
2015-02-06 15:48:28 +01:00
parent 0fc3ca3897
commit cc71a41e8b
+16 -1
View File
@@ -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"""