代码使用
在Python中,使用函数 odoo._():
title = _("Bank Accounts")
在JavaScript中,使用函数 odoo.web._t():
title = _t("Bank Accounts")
代码示例
_("Scheduled meeting with %s") % invitee.name
尽量全文翻译:
# 允许修改在翻译中数量的位置
_("You have %s invoices wainting") % len(invoices)
_.str.sprintf(_t("You have %s invoices wainting"), invoices.length);
# 全句可理解
_("Reference of the document that generated " + \
"this sales order request.")
不要按英文的方式设置词汇的复数,各种语言有不同的复数形式:
if invoice_count > 1:
msg = _("You have %s invoices") % invoice_count
else:
msg = _("You have %s invoice") % invoice_count
翻译方法
【示例一】
翻译文件:/odoo/addons/product/i18n/zh_CN.po
#. module: product
#: model:ir.model.fields,field_description:product.field_product_category__product_count
msgid "# Products"
msgstr "# 产品"
代码文件:/odoo/addons/product/models/product.py
product_count = fields.Integer(
'# Products', compute='_compute_product_count',
help="The number of products under this category (Does not consider the children categories)"
)
【示例二】
翻译文件:/odoo/addons/product/i18n/zh_CN.po
#. module: product
#: code:addons/product/models/product_pricelist.py:0
#, python-format
msgid "%s %% discount"
msgstr "%s %% 折扣"
代码文件:/odoo/addons/product/models/product_pricelist.py
item.price = _("%s %% discount") % (item.percent_price)
【示例三】
翻译文件:/odoo/addons/product/i18n/zh_CN.po
#. module: product
#: code:addons/product/models/product_pricelist.py:0
#, python-format
msgid "%s %% discount and %s surcharge"
msgstr "%s %% 折扣 及 %s 附加费"
代码文件:/odoo/addons/product/models/product_pricelist.py
item.price = _("%s %% discount and %s surcharge") % (item.price_discount, item.price_surcharge)
【示例四】
翻译文件:/odoo/addons/product/i18n/zh_CN.po
#. module: product
#: model:ir.model,name:product.model_product_attribute
#: model_terms:ir.ui.view,arch_db:product.product_attribute_view_form
#: model_terms:ir.ui.view,arch_db:product.product_template_attribute_value_view_form
msgid "Product Attribute"
msgstr "产品属性"
代码文件:/odoo/addons/product/views/product_attribute_views.xml
<form string="Product Attribute">
...
</form>
<form string="Product Attribute" create="0" delete="0">
...
</form>