1. 程式人生 > >Odoo11匯入中文翻譯報錯

Odoo11匯入中文翻譯報錯

Odoo11通過exe安裝包的方式安裝到Win7上之後,接連出現幾個問題。匯入翻譯的時候報錯:write() argument must be str, not bytes

檢視日誌如下:

2018-07-29 14:32:32,919 12068 INFO postgres werkzeug: 127.0.0.1 - - [29/Jul/2018 14:32:32] "GET /web/webclient/locale/zh_TW HTTP/1.1" 500 - 2018-07-29 14:32:32,929 12068 ERROR postgres werkzeug: Error on request: Traceback (most recent call last):

這個問題還是因為字元編碼引起的。

解決辦法:

\server\odoo\addons\base\module\wizard\base_import_language.py,程式碼檢視如下:

class BaseLanguageImport(models.TransientModel):
    _name = "base.language.import"
    _description = "Language Import"

    name = fields.Char('Language Name', required=True)
    code = fields.Char('ISO Code', size=5, required=True,
                       help="ISO Language and Country code, e.g. en_US")
    data = fields.Binary('File', required=True)
    filename = fields.Char('File Name', 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")

    @api.multi
    def import_lang(self):
        this = self[0]
        this = this.with_context(overwrite=this.overwrite)
        with TemporaryFile('wb+') 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