diff options
| author | qsm-odoo <qsm@odoo.com> | 2017-07-27 11:02:28 +0200 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2017-07-27 14:31:42 +0200 |
| commit | 16f0e5031835765dcfed84a250119ea0f15eb30a (patch) | |
| tree | 58263771eb0882e4ea580bab39953ca7340198e3 /addons/web_editor/static/src/js/base.js | |
| parent | 519ed866d7fb3cf6fe0078f2ee2c27d96a46dd9b (diff) | |
[REF] web, web_editor, website: always let session load translations
Before this commit, the session object was responsible for loading the
translations in the backend only. There was then ugly code in web_editor
(which is also loaded in backend...) which was doing "if frontend then
load translations by myself". This code was also translating templates
while this is the qweb object's job. Now session is always responsible
for loading translation.
Note: the session object should be refactored/split.
Diffstat (limited to 'addons/web_editor/static/src/js/base.js')
| -rw-r--r-- | addons/web_editor/static/src/js/base.js | 46 |
1 files changed, 3 insertions, 43 deletions
diff --git a/addons/web_editor/static/src/js/base.js b/addons/web_editor/static/src/js/base.js index 4368f6de274..a241905c631 100644 --- a/addons/web_editor/static/src/js/base.js +++ b/addons/web_editor/static/src/js/base.js @@ -1,10 +1,8 @@ odoo.define('web_editor.base', function (require) { "use strict"; -var core = require('web.core'); var ajax = require('web.ajax'); -var qweb = core.qweb; -var _t = core._t; +var session = require('web.session'); var get_context = function (dict) { var html = document.documentElement; @@ -17,59 +15,21 @@ var get_context = function (dict) { var data = { 'get_context': get_context, - 'url_translations': '/web/webclient/translations', }; var dom_ready = $.Deferred(); $(document).ready(function () { dom_ready.resolve(data); // fix for ie - if($.fn.placeholder) $('input, textarea').placeholder(); + if ($.fn.placeholder) $('input, textarea').placeholder(); }); data.dom_ready = dom_ready; // todo: remove and load a bundle of translated templates -var all_ready; data.ready = function () { - if (!all_ready) { - all_ready = $.when(dom_ready, ajax.loadXML()).then(function () { - // TODO find a better way to find if we are in the backend or not - // We don't load translation if we are in the backend since it's already done by the webclient - if (!$(document).find('.o_web_client').length) { - return load_translations(); - } - }); - } else if(all_ready.state() === "resolved") { // can add async template - all_ready = $.when(dom_ready, ajax.loadXML()); - } - return all_ready; + return $.when(dom_ready, session.is_bound, ajax.loadXML()); }; -function load_translations() { - function translate_node(node) { - if(node.nodeType === 3) { // TEXT_NODE - if(node.nodeValue.match(/\S/)) { - var space = node.nodeValue.match(/^([\s]*)([\s\S]*?)([\s]*)$/); - node.nodeValue = space[1] + $.trim(_t(space[2])) + space[3]; - } - } - else if(node.nodeType === 1 && node.hasChildNodes()) { // ELEMENT_NODE - _.each(node.childNodes, translate_node); - } - } - return ajax.jsonRpc(data.url_translations, 'call', { - 'mods': ['web_editor'], - 'lang': data.get_context().lang - }) - .then(function (trans) { - _t.database.set_bundle(trans); - }).then(function () { - var keys = _.keys(qweb.templates); - for (var i = 0; i < keys.length; i++) { - translate_node(qweb.templates[keys[i]]); - } - }).promise(); -} return dom_ready; }); |
