簡體   English   中英

導出 Python 變量翻譯不起作用

[英]Export Python variable translations not working

我正在 Odoo 13 中開發一個自定義模塊來生成個性化的 XMLS 報告,為此我使用OCA 的 Base Report XLSX 問題是,在為翻譯生成 PO 文檔時,它無法識別我明確標記為導出白色“_()”的變量,即使我遵循了官方文檔中的所有指示(我認為)。

自定義模塊代碼:

# -*- coding: utf-8 -*-
from odoo import models, _
class PayrollBatchReportXLSX(models.AbstractModel):
    _name = 'report.company_payroll.payroll_batch_report'
    _inherit = 'report.report_xlsx.abstract'
    def generate_xlsx_report(self, workbook, data, lines):
        sheet = workbook.add_worksheet('Payroll Batch XLSX Report')
        sheet.write(0, 0, _("ACCOUNT"))
        sheet.write(0, 1, _("DEBIT"))
        sheet.write(0, 2, _("CREDIT"))
        sheet.write(0, 3, _("NAME"))
        line_index = 0
        for line_item in lines.slip_ids.line_ids:
            if line_item.salary_rule_id.category_id.code in ['L10N_HN_NET']:
                sheet.write(line_index+1, 2, line_item.total)
                line_index += 1
        for index, employee in enumerate(lines.slip_ids.employee_id):
            sheet.write(index+1, 3, employee.name.upper())
            if employee.bank_account_id.acc_number:
                sheet.write(index+1, 0, employee.bank_account_id.acc_number)

這是生成的 PO 文件:

# Translation of Odoo Server.
# This file contains the translation of the following modules:
#  * company_payroll
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-05-04 16:17+0000\n"
"PO-Revision-Date: 2022-05-04 16:17+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: company_payroll
#: model:ir.actions.report,print_report_name:company_payroll.payroll_batch_xlsx_report
msgid "'Payroll batch - %s' % (object.name)"
msgstr "'Nómina en lote - %s' % (object.name)"
#. module: company_payroll
#: model:ir.model.fields,field_description:company_payroll.field_report_company_payroll_payroll_batch_report__display_name
msgid "Display Name"
msgstr "Mostrar nombre"
#. module: company_payroll
#: model:ir.model.fields,field_description:company_payroll.field_report_company_payroll_payroll_batch_report__id
msgid "ID"
msgstr ""
#. module: company_payroll
#: model:ir.model.fields,field_description:company_payroll.field_report_company_payroll_payroll_batch_report____last_update
msgid "Last Modified on"
msgstr "Última modificación en"
#. module: company_payroll
#: model:ir.actions.report,name:company_payroll.payroll_batch_xlsx_report
msgid "Payroll Batch XLSX Report"
msgstr "Reporte de nómina por lote"
#. module: company_payroll
#: model:ir.model,name:company_payroll.model_report_company_payroll_payroll_batch_report
msgid "report.company_payroll.payroll_batch_report"
msgstr ""

如您所見,要翻譯的變量(“_("ACCOUNT")"、"_("DEBIT")" 等)沒有顯示在任何地方。 我希望你能幫助我,在此先感謝。

兩個月后,我終於找到了答案,碰巧 Odoo 沒有提取翻譯,因為我的模塊名稱由連字符 ( - ) 分隔,並且由於某種原因,這使得 Odoo 無法識別我要翻譯的字段。 只需將連字符短划線替換為下划線 ( _ )。

感謝在評論中回答我的人(似乎那些被刪除了)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM