[merge] improvements to i18n
bzr revid: nicolas.vanhoren@openerp.com-20110816132843-v75tbf1aola44j1d
This commit is contained in:
@@ -160,22 +160,39 @@ class WebClient(openerpweb.Controller):
|
||||
|
||||
@openerpweb.jsonrequest
|
||||
def translations(self, req, mods, lang):
|
||||
lang_model = req.session.model('res.lang')
|
||||
ids = lang_model.search([("code", "=", lang)])
|
||||
if ids:
|
||||
lang_obj = lang_model.read(ids[0], ["direction", "date_format", "time_format",
|
||||
"grouping", "decimal_point", "thousands_sep"])
|
||||
else:
|
||||
lang_obj = None
|
||||
|
||||
if lang.count("_") > 0:
|
||||
separator = "_"
|
||||
else:
|
||||
separator = "@"
|
||||
langs = lang.split(separator)
|
||||
langs = [separator.join(langs[:x]) for x in range(1, len(langs) + 1)]
|
||||
|
||||
transs = {}
|
||||
for addon_name in mods:
|
||||
transl = {"messages":[]}
|
||||
transs[addon_name] = transl
|
||||
f_name = os.path.join(openerpweb.path_addons, addon_name, "po", lang + ".po")
|
||||
if not os.path.exists(f_name):
|
||||
continue
|
||||
try:
|
||||
with open(f_name) as t_file:
|
||||
po = read_po(t_file)
|
||||
except:
|
||||
continue
|
||||
for x in po:
|
||||
if x.id:
|
||||
transl["messages"].append({'id': x.id, 'string': x.string})
|
||||
return {"modules": transs}
|
||||
for l in langs:
|
||||
f_name = os.path.join(openerpweb.path_addons, addon_name, "po", l + ".po")
|
||||
if not os.path.exists(f_name):
|
||||
continue
|
||||
try:
|
||||
with open(f_name) as t_file:
|
||||
po = read_po(t_file)
|
||||
except:
|
||||
continue
|
||||
for x in po:
|
||||
if x.id and x.string:
|
||||
transl["messages"].append({'id': x.id, 'string': x.string})
|
||||
return {"modules": transs,
|
||||
"lang_parameters": lang_obj}
|
||||
|
||||
|
||||
class Database(openerpweb.Controller):
|
||||
|
||||
@@ -566,6 +566,12 @@ openerp.base.OldWidget = openerp.base.Widget.extend({
|
||||
openerp.base.TranslationDataBase = openerp.base.Class.extend({
|
||||
init: function() {
|
||||
this.db = {};
|
||||
this.parameters = {"direction": 'ltr',
|
||||
"date_format": '%m/%d/%Y',
|
||||
"time_format": '%H:%M:%S',
|
||||
"grouping": "[]",
|
||||
"decimal_point": ".",
|
||||
"thousands_sep": ","};
|
||||
},
|
||||
set_bundle: function(translation_bundle) {
|
||||
var self = this;
|
||||
@@ -577,6 +583,9 @@ openerp.base.TranslationDataBase = openerp.base.Class.extend({
|
||||
_.each(modules, function(name) {
|
||||
self.add_module_translation(translation_bundle.modules[name]);
|
||||
});
|
||||
if (translation_bundle.lang_parameters) {
|
||||
this.parameters = translation_bundle.lang_parameters;
|
||||
}
|
||||
},
|
||||
add_module_translation: function(mod) {
|
||||
var self = this;
|
||||
@@ -884,7 +893,6 @@ openerp.base.Session = openerp.base.CallbackEnabled.extend( /** @lends openerp.b
|
||||
openerp[mod] = {};
|
||||
// init module mod
|
||||
if(openerp._openerp[mod] != undefined) {
|
||||
openerp._openerp[mod]._T = openerp.base._t.database.build_translation_function();
|
||||
openerp._openerp[mod](openerp);
|
||||
this.module_loaded[mod] = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user