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'}
예제 #3
0
 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'}
예제 #4
0
    def import_lang(self):
        this = self[0]
        this = this.with_context(overwrite=this.overwrite)
        with TemporaryFile('w+') as buf:
            try:
                buf.write(base64.decodestring(this.data))

                # now we determine the file format
                buf.seek(0)
                fileformat = os.path.splitext(this.filename)[-1][1:].lower()

                tools.trans_load_data(this._cr, buf, fileformat, this.code,
                                      lang_name=this.name, context=this._context)
            except Exception as 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))
        return True
예제 #5
0
    def import_lang(self):
        this = self[0]
        with TemporaryFile('wb+') as buf:
            try:
                buf.write(base64.decodebytes(this.data))

                # now we determine the file format
                buf.seek(0)
                fileformat = os.path.splitext(this.filename)[-1][1:].lower()

                Lang = self.env["res.lang"]
                lang = Lang._activate_lang(self.code) or Lang._create_lang(
                    self.code, lang_name=self.name)

                tools.trans_load_data(this._cr,
                                      buf,
                                      fileformat,
                                      this.code,
                                      overwrite=self.overwrite)
            except ProgrammingError as e:
                _logger.exception(
                    'File unsuccessfully imported, due to a malformed file.')

                with closing(sql_db.db_connect(
                        self._cr.dbname).cursor()) as cr:
                    raise UserError(
                        _('File %r not imported due to a malformed file.\n\n'
                          'This issue can be caused by duplicates entries who are referring to the same field. '
                          'Please check the content of the file you are trying to import.\n\n'
                          'Technical Details:\n%s') %
                        (self.filename, tools.ustr(e)))
            except Exception as e:
                _logger.exception(
                    'File unsuccessfully imported, due to format mismatch.')
                raise UserError(
                    _('File %r not imported due to format mismatch or a malformed file.'
                      ' (Valid formats are .csv, .po, .pot)\n\nTechnical Details:\n%s') % \
                    (this.filename, tools.ustr(e))
                )
        return True