问题出在模式上——也许 shell 正在为你扩展它。
通常 - 最好在模式中避免路径分隔符(无论是 / 还是 \)。
如果您需要始终将特定选项传递给 makemessages 命令,您可以考虑使用自己的包装器,例如我自己使用的包装器:
from django.conf import settings
from django.core.management.base import BaseCommand
from django.core.management import call_command
class Command(BaseCommand):
help = "Scan i18n messages without going into externals."
def handle(self, *args, **options):
call_command('makemessages',
all=True,
extensions=['html', 'inc'],
ignore_patterns=['externals*'])
这可以节省您的打字时间,并为在整个项目中扫描消息提供一个通用入口点(您的翻译同事不会因为丢失某些参数而破坏翻译)。
不要删除旧的 .po 文件,一旦你从完全不需要的(即来自 'django' 目录的那些)消息中清除它。这允许 gettext 回收旧的未使用消息,一旦它们再次被使用(或类似的,将被标记为 #, fuzzy。
编辑 - 正如 mt4x 所指出的 - 上面的包装器不允许将选项传递给被包装的命令。这很容易解决:
from django.core.management import call_command
from django.core.management.commands.makemessages import (
Command as MakeMessagesCommand
)
class Command(MakeMessagesCommand):
help = "Scan i18n messages without going into externals."
def handle(self, *args, **options):
options['all'] = True
options['extensions'] = ['html', 'inc']
if 'ignore_patterns' not in options:
options['ignore_patterns'] = []
options['ignore_patterns'] += ['externals*']
call_command('makemessages', **options)
因此 - 您可以修复需要修复的部分,并灵活调整其余部分。
这不需要像上面那样盲目覆盖,还需要对传递给命令的参数进行一些条件编辑 - 将某些内容附加到列表或仅在缺少时添加。