Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using plural form for Russian localization

I try to use the plural form in Russian language, but Russian has two forms of word for plural words (for example: "1 курс" = 1 course, "2 курса" = 2 courses, but "5 курсов" = 5 courses).

Django supports this peculiarity and specifies plural form using this algorithm (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"

Description of plural form looks like this (django.po):

msgid "%(курс) курс"
msgid_plural "%(курс) курса"
msgstr[0] "%(курс) курс"
msgstr[1] "%(курс) курса"
msgstr[2] "%(курс) курсов"

How do I use this in templates? Something like this {% sometag word="курс" counter=courses|lenht %}? is there default tag, or do I need to implement this tag by myself?

like image 775
Deadly Avatar asked Mar 18 '12 05:03

Deadly


1 Answers

You need to use blocktrans as hinted by Thomasz. From the blocktrans documentation:

This tag also provides for pluralization. To use it:

Designate and bind a counter value with the name count. This value will be the one used to select the right plural form. Specify both the singular and plural forms separating them with the {% plural %} tag within the {% blocktrans %} and {% endblocktrans %} tags.

An example:

{% blocktrans count counter=list|length %} There is only one {{ name
}} object. {% plural %} There are {{ counter }} {{ name }} objects. {%
endblocktrans %}

A more complex example:

 {% blocktrans with amount=article.price count years=i.length %} That
 will cost $ {{ amount }} per year. {% plural %} That will cost $ {{
 amount }} per {{ years }} years. {% endblocktrans %}
like image 161
Burhan Khalid Avatar answered Oct 02 '22 16:10

Burhan Khalid