diff --git a/addons/web/static/lib/qweb/qweb2.js b/addons/web/static/lib/qweb/qweb2.js index 1ec2a37c02d..9845889a0b7 100644 --- a/addons/web/static/lib/qweb/qweb2.js +++ b/addons/web/static/lib/qweb/qweb2.js @@ -55,7 +55,7 @@ var QWeb2 = { if (o !== null && o !== undefined) { if (o.constructor === Array) { if (o[1] !== null && o[1] !== undefined) { - return ' ' + o[0] + '="' + this.html_escape(o[1], true) + '"'; + return this.format_attribute(o[0], o[1]); } } else if (typeof o === 'object') { var r = ''; @@ -69,6 +69,9 @@ var QWeb2 = { } return ''; }, + format_attribute: function(name, value) { + return ' ' + name + '="' + this.html_escape(value, true) + '"'; + }, extend: function(dst, src, exclude) { for (var p in src) { if (src.hasOwnProperty(p) && !(exclude && this.arrayIndexOf(exclude, p) !== -1)) { @@ -193,7 +196,7 @@ QWeb2.Engine = (function() { this.reserved_words = QWeb2.RESERVED_WORDS.slice(0); this.actions_precedence = QWeb2.ACTIONS_PRECEDENCE.slice(0); this.word_replacement = QWeb2.tools.extend({}, QWeb2.WORD_REPLACEMENT); - this.format_text_node = null; + this.preprocess_node = null; for (var i = 0; i < arguments.length; i++) { this.add_template(arguments[i]); } @@ -437,6 +440,9 @@ QWeb2.Element = (function() { } } } + if (this.engine.preprocess_node) { + this.engine.preprocess_node.call(this); + } } QWeb2.tools.extend(Element.prototype, { @@ -472,11 +478,7 @@ QWeb2.Element = (function() { switch (this.node.nodeType) { case 3: case 4: - var text = this.node.data; - if (this.engine.format_text_node) { - text = this.engine.format_text_node.call(this, text); - } - this.top_string(text); + this.top_string(this.node.data); break; case 1: this.compile_element(); diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index e5e1bc4a066..9d88a8af7f2 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -1233,18 +1233,34 @@ openerp.web.qweb.default_dict = { '_' : _, '_t' : openerp.web._t }; -openerp.web.qweb.format_text_node = function (s) { - // Note that 'this' is the Qweb Node of the text - var translation = this.node.parentNode.attributes['t-translation']; - if (translation && translation.value === 'off') { - return s; +openerp.web.qweb.preprocess_node = function() { + // Note that 'this' is the Qweb Node + switch (this.node.nodeType) { + case 3: + case 4: + // Text and CDATAs + var translation = this.node.parentNode.attributes['t-translation']; + if (translation && translation.value === 'off') { + return; + } + var ts = _.str.trim(this.node.data); + if (ts.length === 0) { + return; + } + var tr = openerp.web._t(ts); + if (tr !== ts) { + this.node.data = tr; + } + break; + case 1: + // Element + var attr, attrs = ['label', 'title', 'alt']; + while (attr = attrs.pop()) { + if (this.attributes[attr]) { + this.attributes[attr] = openerp.web._t(this.attributes[attr]); + } + } } - var ts = _.str.trim(s); - if (ts.length === 0) { - return s; - } - var tr = openerp.web._t(ts); - return tr === ts ? s : tr; }; /** Jquery extentions */