[IMP] Added cli args to load one or more languages translation terms automatically.
Mainly used to automate languages installation at DB initialization. bzr revid: jth@openerp.com-20101020144248-q20vnt72ovx3md96
This commit is contained in:
parent
54ae6b5875
commit
2272c189d9
|
@ -436,7 +436,7 @@ class module(osv.osv):
|
||||||
self.write(cr, uid, [id], {'category_id': p_id})
|
self.write(cr, uid, [id], {'category_id': p_id})
|
||||||
|
|
||||||
def update_translations(self, cr, uid, ids, filter_lang=None, context={}):
|
def update_translations(self, cr, uid, ids, filter_lang=None, context={}):
|
||||||
logger = netsvc.Logger()
|
logger = logging.getLogger('i18n')
|
||||||
if not filter_lang:
|
if not filter_lang:
|
||||||
pool = pooler.get_pool(cr.dbname)
|
pool = pooler.get_pool(cr.dbname)
|
||||||
lang_obj = pool.get('res.lang')
|
lang_obj = pool.get('res.lang')
|
||||||
|
@ -456,13 +456,15 @@ class module(osv.osv):
|
||||||
if len(lang) > 5:
|
if len(lang) > 5:
|
||||||
raise osv.except_osv(_('Error'), _('You Can Not Load Translation For language Due To Invalid Language/Country Code'))
|
raise osv.except_osv(_('Error'), _('You Can Not Load Translation For language Due To Invalid Language/Country Code'))
|
||||||
iso_lang = tools.get_iso_codes(lang)
|
iso_lang = tools.get_iso_codes(lang)
|
||||||
f = os.path.join(modpath, 'i18n', iso_lang + '.po')
|
fn = os.path.join(modpath, 'i18n', iso_lang + '.po')
|
||||||
if not os.path.exists(f) and iso_lang.find('_') != -1:
|
if not os.path.exists(fn) and iso_lang.find('_') != -1:
|
||||||
f = os.path.join(modpath, 'i18n', iso_lang.split('_')[0] + '.po')
|
|
||||||
iso_lang = iso_lang.split('_')[0]
|
iso_lang = iso_lang.split('_')[0]
|
||||||
if os.path.exists(f):
|
fn = os.path.join(modpath, 'i18n', iso_lang + '.po')
|
||||||
logger.notifyChannel("i18n", netsvc.LOG_INFO, 'module %s: loading translation file for language %s' % (mod.name, iso_lang))
|
if os.path.exists(fn):
|
||||||
tools.trans_load(cr.dbname, f, lang, verbose=False, context=context)
|
logger.info('module %s: loading translation file for language %s' % (mod.name, iso_lang))
|
||||||
|
tools.trans_load(cr.dbname, fn, lang, verbose=False, context=context)
|
||||||
|
else:
|
||||||
|
logger.warn('module %s: translation file not found %s' % (mod.name, fn))
|
||||||
|
|
||||||
def check(self, cr, uid, ids, context=None):
|
def check(self, cr, uid, ids, context=None):
|
||||||
logger = logging.getLogger('init')
|
logger = logging.getLogger('init')
|
||||||
|
|
|
@ -119,13 +119,21 @@ if not ( tools.config["stop_after_init"] or \
|
||||||
if tools.config['db_name']:
|
if tools.config['db_name']:
|
||||||
for dbname in tools.config['db_name'].split(','):
|
for dbname in tools.config['db_name'].split(','):
|
||||||
db,pool = pooler.get_db_and_pool(dbname, update_module=tools.config['init'] or tools.config['update'], pooljobs=False)
|
db,pool = pooler.get_db_and_pool(dbname, update_module=tools.config['init'] or tools.config['update'], pooljobs=False)
|
||||||
|
cr = db.cursor()
|
||||||
|
|
||||||
if tools.config["test_file"]:
|
if tools.config["test_file"]:
|
||||||
logger.info('loading test file %s', tools.config["test_file"])
|
logger.info('loading test file %s', tools.config["test_file"])
|
||||||
cr = db.cursor()
|
|
||||||
tools.convert_yaml_import(cr, 'base', file(tools.config["test_file"]), {}, 'test', True)
|
tools.convert_yaml_import(cr, 'base', file(tools.config["test_file"]), {}, 'test', True)
|
||||||
cr.rollback()
|
cr.rollback()
|
||||||
|
|
||||||
|
if tools.config['load_language']:
|
||||||
|
for lang in tools.config['load_language'].split(','):
|
||||||
|
tools.load_language(cr, lang)
|
||||||
|
|
||||||
pool.get('ir.cron')._poolJobs(db.dbname)
|
pool.get('ir.cron')._poolJobs(db.dbname)
|
||||||
|
|
||||||
|
cr.close()
|
||||||
|
|
||||||
#----------------------------------------------------------
|
#----------------------------------------------------------
|
||||||
# translation stuff
|
# translation stuff
|
||||||
#----------------------------------------------------------
|
#----------------------------------------------------------
|
||||||
|
|
|
@ -58,6 +58,7 @@ class configmanager(object):
|
||||||
'xmlrpcs': True,
|
'xmlrpcs': True,
|
||||||
'translate_in': None,
|
'translate_in': None,
|
||||||
'translate_out': None,
|
'translate_out': None,
|
||||||
|
'load_language': None,
|
||||||
'language': None,
|
'language': None,
|
||||||
'pg_path': None,
|
'pg_path': None,
|
||||||
'admin_passwd': 'admin',
|
'admin_passwd': 'admin',
|
||||||
|
@ -206,6 +207,8 @@ class configmanager(object):
|
||||||
"Option '-l' is mandatory in case of importation"
|
"Option '-l' is mandatory in case of importation"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
group.add_option('--load-language', dest="load_language",
|
||||||
|
help="specifies the languages for the translations you want to be loaded")
|
||||||
group.add_option('-l', "--language", dest="language",
|
group.add_option('-l', "--language", dest="language",
|
||||||
help="specify the language of the translation file. Use it with --i18n-export or --i18n-import")
|
help="specify the language of the translation file. Use it with --i18n-export or --i18n-import")
|
||||||
group.add_option("--i18n-export", dest="translate_out",
|
group.add_option("--i18n-export", dest="translate_out",
|
||||||
|
@ -283,6 +286,7 @@ class configmanager(object):
|
||||||
|
|
||||||
keys = [
|
keys = [
|
||||||
'language', 'translate_out', 'translate_in', 'debug_mode', 'smtp_ssl',
|
'language', 'translate_out', 'translate_in', 'debug_mode', 'smtp_ssl',
|
||||||
|
'load_language',
|
||||||
'stop_after_init', 'logrotate', 'without_demo', 'netrpc', 'xmlrpc', 'syslog',
|
'stop_after_init', 'logrotate', 'without_demo', 'netrpc', 'xmlrpc', 'syslog',
|
||||||
'list_db', 'xmlrpcs',
|
'list_db', 'xmlrpcs',
|
||||||
'test_file', 'test_disable', 'test_commit', 'test_report_directory'
|
'test_file', 'test_disable', 'test_commit', 'test_report_directory'
|
||||||
|
|
|
@ -898,5 +898,18 @@ def resetlocale():
|
||||||
except locale.Error:
|
except locale.Error:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
def load_language(cr, lang):
|
||||||
|
"""Loads a translation terms for a language.
|
||||||
|
Used mainly to automate language loading at db initialization.
|
||||||
|
|
||||||
|
:param lang: language ISO code with optional _underscore_ and l10n flavor (ex: 'fr', 'fr_BE', but not 'fr-BE')
|
||||||
|
:type lang: str
|
||||||
|
"""
|
||||||
|
pool = pooler.get_pool(cr.dbname)
|
||||||
|
language_installer = pool.get('base.language.install')
|
||||||
|
uid = 1
|
||||||
|
oid = language_installer.create(cr, uid, {'lang': lang})
|
||||||
|
language_installer.lang_install(cr, uid, [oid], context=None)
|
||||||
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue