diff --git a/bin/addons/__init__.py b/bin/addons/__init__.py index e008c20b66f..a9238e0843f 100644 --- a/bin/addons/__init__.py +++ b/bin/addons/__init__.py @@ -238,7 +238,11 @@ def load_module_graph(cr, graph, status=None, **kwargs): sys.stdout.flush() pool = pooler.get_pool(cr.dbname) modules = pool.instanciate(m, cr) - cr.execute('select state, demo from ir_module_module where name=%s', (m,)) + + cr.execute('select id from ir_module_module where name=%s', (m,)) + mid = int(cr.rowcount and cr.fetchone()[0] or 0) + + cr.execute('select state, demo from ir_module_module where id=%d', (mid,)) (package_state, package_demo) = (cr.rowcount and cr.fetchone()) or ('uninstalled', False) idref = {} status['progress'] = (float(statusi)+0.4)/len(graph) @@ -270,9 +274,16 @@ def load_module_graph(cr, graph, status=None, **kwargs): tools.convert_csv_import(cr, m, os.path.basename(xml), tools.file_open(opj(m, xml)).read(), idref, noupdate=True) else: tools.convert_xml_import(cr, m, tools.file_open(opj(m, xml)), idref, noupdate=True, **kwargs) - cr.execute('update ir_module_module set demo=%s where name=%s', (True, package.name)) + cr.execute('update ir_module_module set demo=%s where id=%d', (True, mid)) package_todo.append(package.name) - cr.execute("update ir_module_module set state='installed' where state in ('to upgrade', 'to install') and name=%s", (package.name,)) + cr.execute("update ir_module_module set state='installed' where state in ('to upgrade', 'to install') and id=%d", (mid,)) + + cr.commit() + + # Update translations for all installed languages + modobj = pool.get('ir.module.module') + modobj.update_translations(cr, 1, [mid], None) + # check if all model of the module have at least a access rule. # TODO: improve this query which is very slow !!! 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): diff --git a/bin/addons/base/module/wizard/wizard_module_lang_install.py b/bin/addons/base/module/wizard/wizard_module_lang_install.py index 5be3bc076cd..0b3c9c7542b 100644 --- a/bin/addons/base/module/wizard/wizard_module_lang_install.py +++ b/bin/addons/base/module/wizard/wizard_module_lang_install.py @@ -30,6 +30,7 @@ import wizard import tools +import pooler view_form_end = """