[FIX] website: translations for qweb templates not applied.

-Website.tours must be loaded after the translation data:
"website.ready" before the tour ensure that the translations are loaded.

-Translations for qweb templates not applied:
Translate all text nodes in qweb templates when translation data
are loaded.

-Add some translations in website tours.

opw:619786
This commit is contained in:
Goffin Simon 2015-02-22 21:14:15 +01:00
parent 47ca07ba19
commit 092c64b76f
10 changed files with 45 additions and 11 deletions

View File

@ -14,6 +14,7 @@ import werkzeug.wrappers
from PIL import Image from PIL import Image
import openerp import openerp
from openerp.addons.web.controllers.main import WebClient
from openerp.addons.web import http from openerp.addons.web import http
from openerp.http import request, STATIC_CACHE from openerp.http import request, STATIC_CACHE
from openerp.tools import image_save_for_web from openerp.tools import image_save_for_web
@ -276,6 +277,13 @@ class Website(openerp.addons.web.controllers.main.Home):
irt.create(request.cr, request.uid, new_trans) irt.create(request.cr, request.uid, new_trans)
return True return True
@http.route('/website/translations', type='json', auth="public", website=True)
def get_website_translations(self, lang):
module_obj = request.registry['ir.module.module']
module_ids = module_obj.search(request.cr, request.uid, [('name', 'ilike', 'website'), ('state', '=', 'installed')], context=request.context)
modules = [x['name'] for x in module_obj.read(request.cr, request.uid, module_ids, ['name'], context=request.context)]
return WebClient().translations(mods=modules, lang=lang)
@http.route('/website/attach', type='http', auth='user', methods=['POST'], website=True) @http.route('/website/attach', type='http', auth='user', methods=['POST'], website=True)
def attach(self, func, upload=None, url=None, disable_optimization=None): def attach(self, func, upload=None, url=None, disable_optimization=None):
Attachments = request.registry['ir.attachment'] Attachments = request.registry['ir.attachment']

View File

@ -304,14 +304,32 @@
if ($('html').data('website-id')) { if ($('html').data('website-id')) {
website.id = $('html').data('website-id'); website.id = $('html').data('website-id');
website.session = new openerp.Session(); website.session = new openerp.Session();
var modules = ['website']; return openerp.jsonRpc('/website/translations', 'call', {'lang': website.get_context().lang})
return openerp._t.database.load_translations(website.session, modules, website.get_context().lang); .then(function(trans) {
openerp._t.database.set_bundle(trans);});
}
}).then(function () {
var templates = openerp.qweb.templates;
var keys = _.keys(templates);
for (var i = 0; i < keys.length; i++){
treat_node(templates[keys[i]]);
} }
}).promise(); }).promise();
} }
return all_ready; return all_ready;
}; };
function treat_node(node){
if(node.nodeType === 3) {
if(node.nodeValue.match(/\S/)){
node.nodeValue = openerp._t($.trim(node.nodeValue));
}
}
else if(node.nodeType === 1 && node.hasChildNodes()) {
_.each(node.childNodes, function(subnode) {treat_node(subnode);});
}
};
website.inject_tour = function() { website.inject_tour = function() {
// if a tour is active inject tour js // if a tour is active inject tour js
}; };

View File

@ -2,7 +2,8 @@
'use strict'; 'use strict';
var _t = openerp._t; var _t = openerp._t;
var website = openerp.website;
website.ready().done(function() {
openerp.Tour.register({ openerp.Tour.register({
id: 'banner', id: 'banner',
name: _t("Build a page"), name: _t("Build a page"),
@ -114,5 +115,6 @@
}, },
] ]
}); });
});
}()); }());

View File

@ -18,7 +18,6 @@
return this._super.apply(this, arguments).then(function () { return this._super.apply(this, arguments).then(function () {
var $edit_button = $("button[data-action=edit]"); var $edit_button = $("button[data-action=edit]");
$edit_button.removeClass("hidden"); $edit_button.removeClass("hidden");
$edit_button.text("Translate");
if(website.no_editor) { if(website.no_editor) {
$edit_button.removeProp('disabled'); $edit_button.removeProp('disabled');

View File

@ -2,7 +2,8 @@
'use strict'; 'use strict';
var _t = openerp._t; var _t = openerp._t;
var website = openerp.website;
website.ready().done(function() {
openerp.Tour.register({ openerp.Tour.register({
id: 'blog', id: 'blog',
name: _t("Create a blog post"), name: _t("Create a blog post"),
@ -103,5 +104,6 @@
}, },
] ]
}); });
});
}()); }());

View File

@ -2,7 +2,8 @@
'use strict'; 'use strict';
var _t = openerp._t; var _t = openerp._t;
var website = openerp.website;
website.ready().done(function() {
openerp.Tour.register({ openerp.Tour.register({
id: 'event', id: 'event',
name: _t("Create an event"), name: _t("Create an event"),
@ -101,5 +102,6 @@
}, },
] ]
}); });
});
}()); }());

View File

@ -1,6 +1,7 @@
(function () { (function () {
'use strict'; 'use strict';
var website = openerp.website;
website.ready().done(function() {
openerp.Tour.register({ openerp.Tour.register({
id: 'event_buy_tickets', id: 'event_buy_tickets',
name: "Try to buy tickets for event", name: "Try to buy tickets for event",
@ -72,5 +73,6 @@
} }
] ]
}); });
});
}()); }());

View File

@ -1,6 +1,5 @@
(function () { (function () {
'use strict'; 'use strict';
openerp.Tour.register({ openerp.Tour.register({
id: 'shop_buy_product', id: 'shop_buy_product',
name: "Try to buy products", name: "Try to buy products",

View File

@ -2,7 +2,8 @@
'use strict'; 'use strict';
var _t = openerp._t; var _t = openerp._t;
var website = openerp.website;
website.ready().done(function() {
openerp.Tour.register({ openerp.Tour.register({
id: 'shop', id: 'shop',
name: _t("Create a product"), name: _t("Create a product"),
@ -111,5 +112,6 @@
}, },
] ]
}); });
});
}()); }());

View File

@ -1,11 +1,11 @@
(function () { (function () {
'use strict'; 'use strict';
var _t = openerp._t;
var steps = openerp.Tour.tours.shop_buy_product.steps; var steps = openerp.Tour.tours.shop_buy_product.steps;
for (var k=0; k<steps.length; k++) { for (var k=0; k<steps.length; k++) {
if (steps[k].title === "click on add to cart") { if (steps[k].title === "click on add to cart") {
steps.splice(k+1, 0, { steps.splice(k+1, 0, {
title: "click in modal on 'Proceed to checkout' button", title: _t("click in modal on 'Proceed to checkout' button"),
element: '.modal a:contains("Proceed to checkout")', element: '.modal a:contains("Proceed to checkout")',
}); });
break; break;