我正在使用 Django,并且无法使用法语在我的模板中获得正确的复数形式,无论我在 blocktrans 标记中使用什么文本。例如:
{% blocktrans count counter=0 %}
foo
{% plural %}
bars
{% endblocktrans %}
给我bars
而不是foo
。事实上,0 在法语中是单数。
我在模板中使用以下内容检查了语言代码:
{% get_current_language as LANGUAGE_CODE %}
{{ LANGUAGE_CODE }}
它给了我fr
。
以下内容位于我的 django.po 法语翻译文件的标题中:
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
你们有什么想法吗?
最佳答案
好吧,我终于知道这是怎么回事了。因为我输入 blocktrans
的方式,这是我在 django.po
中得到的内容由 python manage.py makemessages -l fr
生成的文件命令:
msgid ""
"\n"
" foo\n"
" "
msgid_plural ""
"\n"
" bars\n"
" "
msgstr[0] ""
msgstr[1] ""
我把类似的东西写为 msgstr[0]
和msgstr[1]
:
msgstr[0] ""
"\n"
" foo\n"
" "
msgstr[1] ""
"\n"
" bars\n"
" "
所以我更新了模板:
{% blocktrans count counter=0 %}
foo
{% plural %}
bars
{% endblocktrans %}
致:
{% blocktrans count counter=0 %}foo{% plural %}bars{% endblocktrans %}
翻译如下:
msgid "foo"
msgid_plural "bars"
msgstr[0] "foo"
msgstr[1] "bars"
看起来您的 django.po
中是否有问题(翻译字符串丢失或为空)那么它会导致模板中出现错误的 0 解释。
我会把它留在那里......希望这有帮助!
关于Django模板翻译: zero is plural in fr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33220269/