Perfected translations integration in the framework

bzr revid: nicolas.vanhoren@openerp.com-20130805151012-wnc7wkyiz0eay5oh
This commit is contained in:
niv-openerp 2013-08-05 17:10:12 +02:00
parent 556deae262
commit 1bd4b62142
3 changed files with 24 additions and 6 deletions

View File

@ -672,11 +672,13 @@ class WebClient(http.Controller):
"lang_parameters": None}
@http.route('/web/webclient/translations', type='json', auth="admin")
def translations(self, mods=None, lang="en"):
def translations(self, mods=None, lang=None):
if mods is None:
m = request.registry.get('ir.module.module')
mods = [x['name'] for x in m.search_read(request.cr, request.uid,
[('state','=','installed')], ['name'])]
if lang is None:
lang = request.context["lang"]
res_lang = request.registry.get('res.lang')
ids = res_lang.search(request.cr, request.uid, [("code", "=", lang)])
lang_params = None

View File

@ -156,10 +156,7 @@ instance.web.Session.include( /** @lends instance.web.Session# */{
});
},
load_translations: function() {
var params = { mods: this.module_list, lang: this.user_context.lang };
return this.rpc('/web/webclient/translations', params).done(function(trans) {
instance.web._t.database.set_bundle(trans);
});
return instance.web._t.database.load_translations(this, this.module_list, this.user_context.lang);
},
load_css: function (files) {
var self = this;

View File

@ -1152,7 +1152,26 @@ openerp.web.TranslationDataBase = openerp.web.Class.extend(/** @lends instance.w
},
get: function(key) {
return this.db[key];
}
},
/**
Loads the translations from an OpenERP server.
@param {openerp.web.Session} session The session object to contact the server.
@param {Array} [modules] The list of modules to load the translation. If not specified,
it will default to all the modules installed in the current database.
@param {Object} [lang] lang The language. If not specified it will default to the language
of the current user.
@returns {jQuery.Deferred}
*/
load_translations: function(session, modules, lang) {
var self = this;
return session.rpc('/web/webclient/translations', {
"mods": modules || null,
"lang": lang || null,
}).done(function(trans) {
self.set_bundle(trans);
});
},
});
openerp.web._t = new openerp.web.TranslationDataBase().build_translation_function();