the translations are now by modules
there are stored in a "i18n" folder of each module bzr revid: christophe@tinyerp.com-20080904135432-5lxn2lisw4yqlevl
This commit is contained in:
+14
-3
@@ -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 !!!
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
+12
-15
@@ -85,19 +85,23 @@ class db(netsvc.Service):
|
||||
cr.commit()
|
||||
cr.close()
|
||||
cr = None
|
||||
pool = pooler.get_pool(db_name, demo,serv.actions[id],
|
||||
pool = pooler.get_pool(db_name, demo, serv.actions[id],
|
||||
update_module=True)
|
||||
if lang and lang != 'en_US':
|
||||
filename = tools.config["root_path"] + "/i18n/" + lang + ".csv"
|
||||
tools.trans_load(db_name, filename, lang)
|
||||
serv.actions[id]['clean'] = True
|
||||
|
||||
cr = sql_db.db_connect(db_name).cursor()
|
||||
|
||||
if lang:
|
||||
modobj = pool.get('ir.module.module')
|
||||
mids = modobj.search(cr, 1, [('state', '=', 'installed')])
|
||||
modobj.update_translations(cr, 1, mids, lang)
|
||||
|
||||
cr.execute('UPDATE res_users SET password=%s, active=True WHERE login=%s', (
|
||||
user_password, 'admin'))
|
||||
cr.execute('select login, password, name ' \
|
||||
'from res_users ' \
|
||||
'order by login')
|
||||
cr.execute('SELECT login, password, name ' \
|
||||
' FROM res_users ' \
|
||||
' ORDER BY login')
|
||||
serv.actions[id]['users'] = cr.dictfetchall()
|
||||
serv.actions[id]['clean'] = True
|
||||
cr.commit()
|
||||
cr.close()
|
||||
except Exception, e:
|
||||
@@ -278,13 +282,6 @@ class db(netsvc.Service):
|
||||
|
||||
def list_lang(self):
|
||||
return tools.scan_languages()
|
||||
import glob
|
||||
file_list = glob.glob(os.path.join(tools.config['root_path'], 'i18n', '*.csv'))
|
||||
def lang_tuple(fname):
|
||||
lang_dict=tools.get_languages()
|
||||
lang = os.path.basename(fname).split(".")[0]
|
||||
return (lang, lang_dict.get(lang, lang))
|
||||
return [lang_tuple(fname) for fname in file_list]
|
||||
|
||||
def server_version(self):
|
||||
""" Return the version of the server
|
||||
|
||||
+1
-1
@@ -638,7 +638,7 @@ def get_languages():
|
||||
|
||||
def scan_languages():
|
||||
import glob
|
||||
file_list = [os.path.splitext(os.path.basename(f))[0] for f in glob.glob(os.path.join(config['root_path'], 'i18n', '*.csv'))]
|
||||
file_list = [os.path.splitext(os.path.basename(f))[0] for f in glob.glob(os.path.join(config['addons_path'], 'base', 'i18n', '*.po'))]
|
||||
lang_dict = get_languages()
|
||||
return [(lang, lang_dict.get(lang, lang)) for lang in file_list]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user