diff options
| author | Fabien Meghazi <fme@openerp.com> | 2012-02-07 14:29:01 +0100 |
|---|---|---|
| committer | Fabien Meghazi <fme@openerp.com> | 2012-02-07 14:29:01 +0100 |
| commit | ce65bc3ac37934a27045e8af3d43fc0accf35f3c (patch) | |
| tree | 5504c739a2a1f66487aefdcfdff5a5b05d68d2ee /addons/web/static/src | |
| parent | b5579eee208bf12a4d591e45f3b5ea21cbec69c0 (diff) | |
[IMP] Add QWeb preprocess_node callback. Translate @label, @title and @alt attributes in web client
bzr revid: fme@openerp.com-20120207132901-ifwnfj6c4mp451tl
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/core.js | 38 |
1 files changed, 27 insertions, 11 deletions
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; - } - var ts = _.str.trim(s); - if (ts.length === 0) { - 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 tr = openerp.web._t(ts); - return tr === ts ? s : tr; }; /** Jquery extentions */ |
