From 278955b20741283746914d9633075a831db890f1 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 20 Oct 2011 11:16:19 +0200 Subject: [PATCH] [ADD] Web client now support template translations bzr revid: fme@openerp.com-20111020091619-1i2nhopdgszsy48q --- addons/web/static/src/js/core.js | 17 +++++++++++++++-- npybabel.py | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 8dfbd68e6de..21a4ca21931 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -10,8 +10,6 @@ if (!console.debug) { } openerp.web.core = function(openerp) { -openerp.web.qweb = new QWeb2.Engine(); -openerp.web.qweb.debug = (window.location.search.indexOf('?debug') !== -1); /** * John Resig Class with factory improvement */ @@ -1040,6 +1038,21 @@ openerp.web.TranslationDataBase = openerp.web.Class.extend(/** @lends openerp.we }); openerp.web._t = new openerp.web.TranslationDataBase().build_translation_function(); +openerp.web.qweb = new QWeb2.Engine(); +openerp.web.qweb.debug = (window.location.search.indexOf('?debug') !== -1); +openerp.web.qweb.format_text_node = function(s) { + // Note that 'this' is the Qweb Node of the text + var translation = this.node.parentElement.attributes['t-translation']; + if (translation && translation.value === 'off') { + return s; + } + var ts = _.trim(s); + if (ts.length === 0) { + return s; + } + var tr = openerp.web._t(ts); + return tr === ts ? s : tr; +} }; diff --git a/npybabel.py b/npybabel.py index 0a3c75025c9..1b2e80a7a67 100755 --- a/npybabel.py +++ b/npybabel.py @@ -54,7 +54,7 @@ def extract_qweb(fileobj, keywords, comment_tags, options): for el in current_element: if "t-js" not in el.attrib and \ not ("t-jquery" in el.attrib and "t-operation" not in el.attrib) and \ - not ("t-trad" in el.attrib and el.attrib["t-trad"].strip() == "off"): + not ("t-translation" in el.attrib and el.attrib["t-translation"].strip() == "off"): handle_text(el.text) iter_elements(el) handle_text(el.tail)