如何仅使用 django manage.py makemessages 创建 .pot 文件

Posted

技术标签:

【中文标题】如何仅使用 django manage.py makemessages 创建 .pot 文件【英文标题】:How to only create .pot files with django manage.py makemessages 【发布时间】:2021-12-03 15:31:10 【问题描述】:

Weblate 有一个名为“更新 PO 文件以匹配 POT (msgmerge)”的插件。我想将 .po 文件的创建委托给 Weblate,并且只使用 manage.py makemessages 来创建 .pot 文件。

manage.py makemessages 有一个--keep-pot 选项,它将.pot 文件添加到输出中。不幸的是,没有保留.pot文件的选项。

【问题讨论】:

【参考方案1】:

可以通过覆盖makemessages 命令的write_po_file 方法来跳过.po 文件的创建。为此,请在management/commands 中创建一个makemessages.py 文件(如Django docs 中所述):

# management/commands/makemessages.py
class Command(makemessages.Command):

    def write_po_file(*args, **kwargs):
        """Overwrite method to do nothing.

        We do not want to interfere with Weblate's
        "Update PO files to match POT (msgmerge)" addon
        """
        pass

【讨论】:

以上是关于如何仅使用 django manage.py makemessages 创建 .pot 文件的主要内容,如果未能解决你的问题,请参考以下文章