[imp] added fallback support for translations

bzr revid: nicolas.vanhoren@openerp.com-20110816125912-5fkm71nb4y6yp3d0
This commit is contained in:
niv-openerp 2011-08-16 14:59:12 +02:00
parent 81ea898b8c
commit 5a34b9fee1
2 changed files with 24 additions and 16 deletions

View File

@ -160,21 +160,6 @@ class WebClient(openerpweb.Controller):
@openerpweb.jsonrequest
def translations(self, req, mods, lang):
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})
lang_model = req.session.model('res.lang')
ids = lang_model.search([("code", "=", lang)])
if ids:
@ -182,6 +167,30 @@ class WebClient(openerpweb.Controller):
"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
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}

View File

@ -893,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;
}