From a357961185fa5313e8f09e9b365e419bc685436c Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers <fp@tinyerp.com> Date: Sun, 17 Oct 2010 17:43:35 +0200 Subject: [PATCH] [FIX] translation terms overwrited bzr revid: fp@tinyerp.com-20101017154335-fhdwj610nkqfez9w --- bin/addons/base/module/module.py | 4 ++-- .../base/module/wizard/base_language_install.py | 11 ++++++----- .../module/wizard/base_language_install_view.xml | 3 ++- bin/tools/translate.py | 12 +++++++----- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/bin/addons/base/module/module.py b/bin/addons/base/module/module.py index 74cd018399cc..b2c2da96d13e 100644 --- a/bin/addons/base/module/module.py +++ b/bin/addons/base/module/module.py @@ -435,7 +435,7 @@ class module(osv.osv): categs = categs[1:] self.write(cr, uid, [id], {'category_id': p_id}) - def update_translations(self, cr, uid, ids, filter_lang=None): + def update_translations(self, cr, uid, ids, filter_lang=None, context={}): logger = netsvc.Logger() if not filter_lang: pool = pooler.get_pool(cr.dbname) @@ -462,7 +462,7 @@ class module(osv.osv): iso_lang = iso_lang.split('_')[0] if os.path.exists(f): logger.notifyChannel("i18n", netsvc.LOG_INFO, 'module %s: loading translation file for language %s' % (mod.name, iso_lang)) - tools.trans_load(cr.dbname, f, lang, verbose=False) + tools.trans_load(cr.dbname, f, lang, verbose=False, context=context) def check(self, cr, uid, ids, context=None): logger = logging.getLogger('init') diff --git a/bin/addons/base/module/wizard/base_language_install.py b/bin/addons/base/module/wizard/base_language_install.py index 7a3b8cc75aa2..a5077f37f4f6 100644 --- a/bin/addons/base/module/wizard/base_language_install.py +++ b/bin/addons/base/module/wizard/base_language_install.py @@ -31,23 +31,24 @@ class base_language_install(osv.osv_memory): _columns = { 'lang': fields.selection(tools.scan_languages(),'Language', required=True), + 'overwrite': fields.boolean('Overwrite Existing Terms', help="If you check this box, your customized translations will be overwrited and replaced by the official ones."), 'state':fields.selection([('init','init'),('done','done')], 'state', readonly=True), } - _defaults = { 'state': 'init', + 'overwrite': False } - def lang_install(self, cr, uid, ids, context): language_obj = self.browse(cr, uid, ids)[0] lang = language_obj.lang if lang: modobj = self.pool.get('ir.module.module') mids = modobj.search(cr, uid, [('state', '=', 'installed')]) - modobj.update_translations(cr, uid, mids, lang) + if language_obj.overwrite: + context = {'overwrite': True} + modobj.update_translations(cr, uid, mids, lang, context or {}) self.write(cr, uid, ids, {'state': 'done'}, context=context) return False - base_language_install() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/bin/addons/base/module/wizard/base_language_install_view.xml b/bin/addons/base/module/wizard/base_language_install_view.xml index 38edf4d4a827..d207ea9ea29f 100644 --- a/bin/addons/base/module/wizard/base_language_install_view.xml +++ b/bin/addons/base/module/wizard/base_language_install_view.xml @@ -19,9 +19,10 @@ </group> <separator orientation="vertical" rowspan="15"/> <group colspan="4"> - <separator string="Load Official Translation" colspan="4"/> + <separator string="Load an Official Translation" colspan="4"/> <group states="init" colspan="4"> <field name="lang" colspan="4"/> + <field name="overwrite" colspan="4" groups="base.group_extended"/> </group> <group states="done" colspan="4"> <label string="The selected language has been successfully installed. diff --git a/bin/tools/translate.py b/bin/tools/translate.py index e2b4d64949e0..f978ecbfd4b3 100644 --- a/bin/tools/translate.py +++ b/bin/tools/translate.py @@ -695,12 +695,12 @@ def trans_generate(lang, modules, dbname=None): cr.close() return out -def trans_load(db_name, filename, lang, strict=False, verbose=True): +def trans_load(db_name, filename, lang, strict=False, verbose=True, context={}): logger = netsvc.Logger() try: fileobj = open(filename,'r') fileformat = os.path.splitext(filename)[-1][1:].lower() - r = trans_load_data(db_name, fileobj, fileformat, lang, strict=strict, verbose=verbose) + r = trans_load_data(db_name, fileobj, fileformat, lang, strict=strict, verbose=verbose, context=context) fileobj.close() return r except IOError: @@ -708,7 +708,7 @@ def trans_load(db_name, filename, lang, strict=False, verbose=True): logger.notifyChannel("i18n", netsvc.LOG_ERROR, "couldn't read translation file %s" % (filename,)) return None -def trans_load_data(db_name, fileobj, fileformat, lang, strict=False, lang_name=None, verbose=True): +def trans_load_data(db_name, fileobj, fileformat, lang, strict=False, lang_name=None, verbose=True, context={}): logger = netsvc.Logger() if verbose: logger.notifyChannel("i18n", netsvc.LOG_INFO, 'loading translation file for language %s' % (lang)) @@ -833,7 +833,8 @@ def trans_load_data(db_name, fileobj, fileformat, lang, strict=False, lang_name= ('res_id', '=', dic['res_id']) ]) if ids: - trans_obj.write(cr, uid, ids, {'value': dic['value']}) + if context.get('overwrite', False): + trans_obj.write(cr, uid, ids, {'value': dic['value']}) else: trans_obj.create(cr, uid, dic) else: @@ -844,7 +845,8 @@ def trans_load_data(db_name, fileobj, fileformat, lang, strict=False, lang_name= ('src', '=', dic['src']) ]) if ids: - trans_obj.write(cr, uid, ids, {'value': dic['value']}) + if context.get('overwrite', False): + trans_obj.write(cr, uid, ids, {'value': dic['value']}) else: trans_obj.create(cr, uid, dic) cr.commit() -- GitLab