From 09de5a26fdb1126bf8e7c1b311967b2e14acaa3d Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Thu, 4 Sep 2008 15:54:32 +0200 Subject: the translations are now by modules there are stored in a "i18n" folder of each module bzr revid: christophe@tinyerp.com-20080904135432-5lxn2lisw4yqlevl --- bin/addons/base/module/module.py | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'bin/addons/base/module/module.py') diff --git a/bin/addons/base/module/module.py b/bin/addons/base/module/module.py index 908b4cdc8f1..15b9a1fe820 100644 --- a/bin/addons/base/module/module.py +++ b/bin/addons/base/module/module.py @@ -40,6 +40,8 @@ import zipimport import wizard import addons +import pooler +import netsvc ver_regexp = re.compile("^(\\d+)((\\.\\d+)*)([a-z]?)((_(pre|p|beta|alpha|rc)\\d*)*)(-r(\\d+))?$") suffix_regexp = re.compile("^(alpha|beta|rc|pre|p)(\\d*)$") @@ -319,19 +321,8 @@ class module(osv.osv): def button_upgrade_cancel(self, cr, uid, ids, context={}): self.write(cr, uid, ids, {'state': 'installed'}) return True - def button_update_translations(self, cr, uid, ids, context={}): - cr.execute('select code from res_lang where translatable=TRUE') - langs = [l[0] for l in cr.fetchall()] - modules = self.read(cr, uid, ids, ['name']) - for module in modules: - files = self.get_module_info(module['name']).get('translations', {}) - for lang in langs: - if files.has_key(lang): - filepath = files[lang] - # if filepath does not contain :// we prepend the path of the module - if filepath.find('://') == -1: - filepath = addons.get_module_resource(module['name'], filepath) - tools.trans_load(filepath, lang) + def button_update_translations(self, cr, uid, ids, context=None): + self.update_translations(cr, uid, ids) return True # update the list of available packages @@ -527,6 +518,28 @@ class module(osv.osv): dep_ids = map(lambda x:x[0],cr.fetchall()) if len(dep_ids): self.action_install(cr,uid,dep_ids,context=context) + + def update_translations(self, cr, uid, ids, filter_lang=None): + logger = netsvc.Logger() + + if not filter_lang: + pool = pooler.get_pool(cr.dbname) + lang_obj=pool.get('res.lang') + lang_ids=lang_obj.search(cr, uid, [('translatable', '=', True)]) + filter_lang= [lang.code for lang in lang_obj.browse(cr, uid, lang_ids)] + elif not isinstance(filter_lang, (list, tuple)): + filter_lang = [filter_lang] + + for mod in self.browse(cr, uid, ids): + if mod.state != 'installed': + continue + + for lang in filter_lang: + f = os.path.join(tools.config['addons_path'], mod.name, 'i18n', lang + '.po') + if os.path.exists(f): + logger.notifyChannel("init", netsvc.LOG_INFO, 'addons %s: loading translation file for language %s' % (mod.name, lang)) + tools.trans_load(cr.dbname, f, lang, verbose=False) + module() class module_dependency(osv.osv): -- cgit v1.2.3