我正在使用 blocktrans 标签呈现一些复数形式;这是模板文件中的相关片段:
{% blocktrans count choice_count=choice_count %}
You have {{ choice_count }} choice:
{% plural %}
You have {{ choice_count }} choices:
{% endblocktrans %}
运行后python manage.py makemessages --all
,这是我的相关片段,例如django.po
文件en
:
msgid ""
"\n"
" You have %(choice_count)s choice:\n"
msgid_plural ""
"\n"
" You have %(choice_count)s choices:\n"
msgstr[0] "You have one choices:"
msgstr[1] "You have %(choice_count)s choice(s):"
但是当我运行时python manage.py compilemessages
,这是我得到的错误消息:
$ ./manage.py compilemessages
processing file django.po in /home/yiqing/repos/training/site/training/locale/en/LC_MESSAGES
/home/yiqing/repos/training/site/training/locale/en/LC_MESSAGES/django.po:60: `msgid' and `msgstr[0]' entries do not both begin with '\n'
msgfmt: found 4 fatal errors
我知道这是因为模板文件中的换行符/空格,并且我知道如何“绕过”它——当我将模板片段更改为例如:
{% blocktrans count choice_count=choice_count %}You have {{ choice_count }} choice:{% plural %}You have {{ choice_count }} choices:{% endblocktrans %}
然后重新运行makemessages
,从消息中删除fuzzy
标记,然后重新运行compilemessages
,它编译得很好。
但是,我的问题是如何保留第一个模板语法并且仍然能够编译消息,因为它极大地提高了模板文件中代码的可读性。