[MERGE] allow overwriting existing terms when importing stand-alone translations

bzr revid: odo@openerp.com-20110919211310-zcndav9xmqm0c5df
This commit is contained in:
Olivier Dony 2011-09-19 23:13:10 +02:00
commit 33b913fb56
2 changed files with 10 additions and 3 deletions

View File

@ -35,9 +35,12 @@ class base_language_import(osv.osv_memory):
'name': fields.char('Language Name',size=64 , required=True),
'code': fields.char('Code (eg:en__US)',size=5 , required=True),
'data': fields.binary('File', required=True),
'overwrite': fields.boolean('Overwrite Existing Terms',
help="If you enable this option, existing translations (including custom ones) "
"will be overwritten and replaced by those in this file"),
}
def import_lang(self, cr, uid, ids, context):
def import_lang(self, cr, uid, ids, context=None):
"""
Import Language
@param cr: the current row, from the database cursor.
@ -45,8 +48,11 @@ class base_language_import(osv.osv_memory):
@param ids: the ID or list of IDs
@param context: A standard dictionary
"""
if context is None:
context = {}
import_data = self.browse(cr, uid, ids)[0]
if import_data.overwrite:
context.update(overwrite=True)
fileobj = TemporaryFile('w+')
fileobj.write(base64.decodestring(import_data.data))
@ -56,7 +62,7 @@ class base_language_import(osv.osv_memory):
fileformat = first_line.endswith("type,name,res_id,src,value") and 'csv' or 'po'
fileobj.seek(0)
tools.trans_load_data(cr, fileobj, fileformat, import_data.code, lang_name=import_data.name)
tools.trans_load_data(cr, fileobj, fileformat, import_data.code, lang_name=import_data.name, context=context)
tools.trans_update_res_ids(cr)
fileobj.close()
return {}

View File

@ -27,6 +27,7 @@
<field name="name" width="200"/>
<field name="code"/>
<field name="data" colspan="4"/>
<field name="overwrite"/>
</group>
<group colspan="8" col="8">
<separator string="" colspan="8"/>