summaryrefslogtreecommitdiff
path: root/bin/addons/base/module
diff options
context:
space:
mode:
authorChristophe Simonis <christophe@tinyerp.com>2008-09-04 15:54:32 +0200
committerChristophe Simonis <christophe@tinyerp.com>2008-09-04 15:54:32 +0200
commit09de5a26fdb1126bf8e7c1b311967b2e14acaa3d (patch)
tree7fb093033ae9143f61ec400b1569a444db42adb3 /bin/addons/base/module
parentb30f507f972e91fcab3b07374c8afc1b419947db (diff)
the translations are now by modules
there are stored in a "i18n" folder of each module bzr revid: christophe@tinyerp.com-20080904135432-5lxn2lisw4yqlevl
Diffstat (limited to 'bin/addons/base/module')
-rw-r--r--bin/addons/base/module/module.py39
-rw-r--r--bin/addons/base/module/wizard/wizard_module_lang_install.py9
-rw-r--r--bin/addons/base/module/wizard/wizard_module_upgrade.py14
3 files changed, 38 insertions, 24 deletions
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 = """<?xml version="1.0"?>
<form string="Language file loaded.">
@@ -55,9 +56,11 @@ view_form = """<?xml version="1.0"?>
class wizard_lang_install(wizard.interface):
def _lang_install(self, cr, uid, data, context):
lang = data['form']['lang']
- if lang and lang != 'en_US':
- filename = tools.config["root_path"] + "/i18n/" + lang + ".csv"
- tools.trans_load(cr.dbname, filename, lang)
+ if lang:
+ pool = pooler.get_pool(cr.dbname)
+ modobj = cr.pool.get('ir.module.module')
+ mids = modobj.search(cr, uid, [('state', '=', 'installed')])
+ modobj.update_translations(cr, uid, mids, lang)
return {}
def _get_language(sel, cr, uid, context):
diff --git a/bin/addons/base/module/wizard/wizard_module_upgrade.py b/bin/addons/base/module/wizard/wizard_module_upgrade.py
index 55432bd44f9..c126a70b12a 100644
--- a/bin/addons/base/module/wizard/wizard_module_upgrade.py
+++ b/bin/addons/base/module/wizard/wizard_module_upgrade.py
@@ -101,14 +101,12 @@ class wizard_info_get(wizard.interface):
mod_obj.download(cr, uid, ids, context=context)
cr.commit()
db, pool = pooler.restart_pool(cr.dbname, update_module=True)
-
- lang_obj=pool.get('res.lang')
- lang_ids=lang_obj.search(cr, uid, [])
- langs=lang_obj.browse(cr, uid, lang_ids)
- for lang in langs:
- if lang.code and lang.code != 'en_US':
- filename=os.path.join(tools.config["root_path"], "i18n", lang.code + ".csv")
- tools.trans_load(cr.dbname, filename, lang.code)
+
+ # Update translations for all installed languages
+ cr = db.cursor()
+ modobj = pool.get('ir.module.module')
+ mids = modobj.search(cr, uid, [('state', '=', 'installed')])
+ modobj.update_translations(cr, uid, mids, None)
return {}
def _config(self, cr, uid, data, context=None):