def import_lang(self, cr, uid, ids, context=None): if context is None: context = {} this = self.browse(cr, uid, ids[0]) if this.overwrite: context = dict(context, overwrite=True) self.env["res.lang"].load_lang(cr, uid, lang=self.code, lang_name=self.name) fileobj = TemporaryFile('w+') try: fileobj.write(base64.decodestring(this.data)) # now we determine the file format fileobj.seek(0) fileformat = os.path.splitext(this.filename)[-1][1:].lower() tools.trans_load_data(cr, fileobj, fileformat, this.code, lang_name=this.name, context=context) except Exception, e: _logger.exception( 'File unsuccessfully imported, due to format mismatch.') raise UserError( _('File not imported due to format mismatch or a malformed file. (Valid formats are .csv, .po, .pot)\n\nTechnical Details:\n%s' ) % tools.ustr(e))
def act_update_automatically(self, cr, uid, ids, context=None): # _logger.warning("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") # this = self.browse(cr, uid, ids)[0] # lang_name = self._get_lang_name(cr, uid, 'vi_VN') # _logger.warning(lang_name) # _logger.warning(this.lang) try: _logger.warning("<<<<<<<<<<<<<<<<<<<< Syn <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") vn_ids = self.pool['res.lang'].search(cr, uid,[('iso_code','=','vi_VN')],context={}) if len(vn_ids) == 0: raise osv.except_osv(_('Error!'), _('No language found')) return {'type': 'ir.actions.act_window_close'} vn_string = self.pool['res.lang'].read(cr, uid, vn_ids, ['name'],context={})[0] _logger.warning(vn_string) _logger.warning("<<<<<<<<<<<<<<<<<<<< Syn <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") buf = cStringIO.StringIO() tools.trans_export('vi_VN', ['all'], buf, 'csv', cr) tools.trans_load_data(cr, buf, 'csv', 'vi_VN', lang_name=vn_string['name']) buf.close() except: return {'type': 'ir.actions.act_window_close'} return {'type': 'ir.actions.act_window_close'}
def import_lang(self, cr, uid, ids, context=None): if context is None: context = {} this = self.browse(cr, uid, ids[0]) if this.overwrite: context = dict(context, overwrite=True) fileobj = TemporaryFile('w+') try: fileobj.write(base64.decodestring(this.data)) # now we determine the file format fileobj.seek(0) first_line = fileobj.readline().strip().replace('"', '').replace( ' ', '') fileformat = first_line.endswith( "type,name,res_id,src,value") and 'csv' or 'po' fileobj.seek(0) tools.trans_load_data(cr, fileobj, fileformat, this.code, lang_name=this.name, context=context) finally: fileobj.close() return True
def act_update(self, cr, uid, ids, context=None): this = self.browse(cr, uid, ids)[0] lang_name = self._get_lang_name(cr, uid, this.lang) buf = io.StringIO() tools.trans_export(this.lang, ['all'], buf, 'csv', cr) tools.trans_load_data(cr, buf, 'csv', this.lang, lang_name=lang_name) buf.close() return {'type': 'ir.actions.act_window_close'}
def act_update(self, cr, uid, ids, context=None): this = self.browse(cr, uid, ids)[0] lang_name = self._get_lang_name(cr, uid, this.lang) buf = cStringIO.StringIO() tools.trans_export(this.lang, ['all'], buf, 'csv', cr) tools.trans_load_data(cr, buf, 'csv', this.lang, lang_name=lang_name) buf.close() return {'type': 'ir.actions.act_window_close'}
def import_lang(self, cr, uid, ids, context=None): if context is None: context = {} this = self.browse(cr, uid, ids[0]) if this.overwrite: context = dict(context, overwrite=True) fileobj = TemporaryFile('w+') try: fileobj.write(base64.decodestring(this.data)) # now we determine the file format fileobj.seek(0) fileformat = os.path.splitext(this.filename)[-1][1:].lower() tools.trans_load_data(cr, fileobj, fileformat, this.code, lang_name=this.name, context=context) except Exception, e: _logger.exception('File unsuccessfully imported, due to format mismatch.') raise UserError(_('File not imported due to format mismatch or a malformed file. (Valid formats are .csv, .po, .pot)\n\nTechnical Details:\n%s') % tools.ustr(e))
def import_lang(self, cr, uid, ids, context=None): if context is None: context = {} this = self.browse(cr, uid, ids[0]) if this.overwrite: context = dict(context, overwrite=True) fileobj = TemporaryFile('w+') try: fileobj.write(base64.decodestring(this.data)) # now we determine the file format fileobj.seek(0) first_line = fileobj.readline().strip().replace('"', '').replace(' ', '') fileformat = first_line.endswith("type,name,res_id,src,value") and 'csv' or 'po' fileobj.seek(0) tools.trans_load_data(cr, fileobj, fileformat, this.code, lang_name=this.name, context=context) finally: fileobj.close() return True
def act_update_automatically(self, cr, uid, ids, context=None): # _logger.warning("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") # this = self.browse(cr, uid, ids)[0] # lang_name = self._get_lang_name(cr, uid, 'vi_VN') # _logger.warning(lang_name) # _logger.warning(this.lang) try: _logger.warning( "<<<<<<<<<<<<<<<<<<<< Syn <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") vn_ids = self.pool['res.lang'].search(cr, uid, [('iso_code', '=', 'vi_VN')], context={}) if len(vn_ids) == 0: raise osv.except_osv(_('Error!'), _('No language found')) return {'type': 'ir.actions.act_window_close'} vn_string = self.pool['res.lang'].read(cr, uid, vn_ids, ['name'], context={})[0] _logger.warning(vn_string) _logger.warning( "<<<<<<<<<<<<<<<<<<<< Syn <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") buf = cStringIO.StringIO() tools.trans_export('vi_VN', ['all'], buf, 'csv', cr) tools.trans_load_data(cr, buf, 'csv', 'vi_VN', lang_name=vn_string['name']) buf.close() except: return {'type': 'ir.actions.act_window_close'} return {'type': 'ir.actions.act_window_close'}