def act_getfile(self): this = self[0] lang = this.lang if this.lang != NEW_LANG_KEY else False mods = sorted(this.mapped('modules.name')) or ['all'] with contextlib.closing(io.BytesIO()) as buf: tools.trans_export(lang, mods, buf, this.format, self._cr) out = base64.encodestring(buf.getvalue()) filename = 'new' if lang: filename = tools.get_iso_codes(lang) elif len(mods) == 1: filename = mods[0] extension = this.format if not lang and extension == 'po': extension = 'pot' name = "%s.%s" % (filename, extension) this.write({'state': 'get', 'data': out, 'name': name}) return { 'type': 'ir.actions.act_window', 'res_model': 'base.language.export', 'view_mode': 'form', 'view_type': 'form', 'res_id': this.id, 'views': [(False, 'form')], 'target': 'new', }
def act_update(self): this = self[0] lang_name = self._get_lang_name(this.lang) with contextlib.closing(io.BytesIO()) as buf: tools.trans_export(this.lang, ['all'], buf, 'csv', self._cr) tools.trans_load_data(self._cr, buf, 'csv', this.lang, lang_name=lang_name) return {'type': 'ir.actions.act_window_close'}
def act_update(self): this = self[0] lang_name = self._get_lang_name(this.lang) with tempfile.NamedTemporaryFile() as buf: tools.trans_export(this.lang, ['all'], buf, 'po', self._cr) tools.trans_load_data(self._cr, buf, 'po', this.lang, lang_name=lang_name) return {'type': 'ir.actions.act_window_close'}
def act_update(self): with tempfile.NamedTemporaryFile() as buf: tools.trans_export(self.lang, ['all'], buf, 'tgz', self._cr) buf.seek(0) tar = tarfile.open(fileobj=buf) for file_info in tar: module_file = tar.extractfile(file_info) tools.trans_load_data(self._cr, module_file, 'po', self.lang, create_empty_translation=True) tar.close() return {'type': 'ir.actions.act_window_close'}