即使一个人,也要活得像军队一样!

Odoo13-- Odoo修改翻译

场景: odoo原生模块翻译不正确,我们想在新模块通过po文件进行翻译且不动原生模块。

方式一:xml视图继承。
这也是最常规的,通过xpath定位找到相关翻译,进行添加属性,或者替换等操作,此时我们的模块可以导出po文件。
此操作不仅适用于字段,还适用于div等标签属性的翻译。

方式二:python后台字段继承。
此方式适用于硬编码,不需要po文件。直接重写字段的定义。

方式三:po文件覆盖。
此方式需要添加配置。需要在config文件中添加overwrite_existing_translations = True
然后在我们的新模块的po文件中重写原模块的翻译。

举例:
原模块po文件:

1
2
3
4
#. module: sale
#: model:ir.model.fields,field_description:sale.field_sale_order__validity_date
msgid "Expiration"
msgstr "到期"

新模块po文件:

1
2
3
4
#. module: sale
#: model:ir.model.fields,field_description:sale.field_sale_order__validity_date
msgid "Expiration"
msgstr "到期时间"

升级新模块即生效。注意:加载翻译不生效,且会变回原有的。

以下为config文件部分配置:

1
2
3
4
5
6
7
8
9
10
11
12
group.add_option('--load-language', dest="load_language",
help="specifies the languages for the translations you want to be loaded")
group.add_option('-l', "--language", dest="language",
help="specify the language of the translation file. Use it with --i18n-export or --i18n-import")
group.add_option("--i18n-export", dest="translate_out",
help="export all sentences to be translated to a CSV file, a PO file or a TGZ archive and exit")
group.add_option("--i18n-import", dest="translate_in",
help="import a CSV or a PO file with translations and exit. The '-l' option is required.")
group.add_option("--i18n-overwrite", dest="overwrite_existing_translations", action="store_true", my_default=False,
help="overwrites existing translation terms on updating a module or importing a CSV or a PO file.")
group.add_option("--modules", dest="translate_modules",
help="specify modules to export. Use in combination with --i18n-export")
-------------本文结束感谢您的阅读-------------