Dea*_*dly 6 django internationalization
我尝试使用俄语的复数形式,但俄罗斯有两种形式的字为多个单词(例如:"1个курс" = 1当然,"2курс а " = 2门课程,但"5курс ов " = 5课程).
Django支持这种特性并使用此算法指定复数形式(django.po headers):
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%"
"10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
Run Code Online (Sandbox Code Playgroud)
复数形式的描述看起来像这样(django.po):
msgid "%(????) ????"
msgid_plural "%(????) ?????"
msgstr[0] "%(????) ????"
msgstr[1] "%(????) ?????"
msgstr[2] "%(????) ??????"
Run Code Online (Sandbox Code Playgroud)
我如何在模板中使用它?像这样的东西{% sometag word="????" counter=courses|lenht %}?有默认标签,还是我需要自己实现这个标签?
你需要使用blocktrans托马斯提示.从blocktrans文档:
该标签还提供复数化.要使用它:
使用名称计数指定和绑定计数器值.该值将是用于选择正确的复数形式的值.使用{%blocktrans%}和{%endblocktrans%}标记中的{%plural%}标记指定单数和复数形式.
一个例子:
{% blocktrans count counter=list|length %} There is only one {{ name
}} object. {% plural %} There are {{ counter }} {{ name }} objects. {%
endblocktrans %}
Run Code Online (Sandbox Code Playgroud)
一个更复杂的例子:
{% blocktrans with amount=article.price count years=i.length %} That
will cost $ {{ amount }} per year. {% plural %} That will cost $ {{
amount }} per {{ years }} years. {% endblocktrans %}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2848 次 |
| 最近记录: |