I want to use a custom Plural-Forms scheme in my django.po for Russian, but when I change it, it does not affect the results of ungettext.
I’ve found out that if I use the same translation file without Django, Plural-Forms works correctly.
Here is the django.po file.
msgid ""
msgstr ""
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-09-18 01:26+0000\n"
"Language: ru\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=4; plural=(n==1 ? 0 : n%10==1 && n%100!=11 ? 1 : n"
"%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 2 : 3)\n"
#: testapp/test.py:5
#, python-format
msgid "One new notification."
msgid_plural "%(count)s new notifications."
msgstr[0] "Одно новое оповещение."
msgstr[1] "%(count)s новое оповещение."
msgstr[2] "%(count)s новых оповещения."
msgstr[3] "%(count)s новых оповещений."
If I run this
import gettext
filename = "testp/conf/locale/ru/LC_MESSAGES/django.mo"
trans = gettext.GNUTranslations(open( filename, "rb" ) )
trans.install()
def translated_message(notifications_count):
return trans.ungettext(
"One new notification.",
"%(count)s new notifications.",
notifications_count
) % {"count": notifications_count}
print translated_message(1)
print translated_message(2)
print translated_message(5)
print translated_message(51)
The following is printed:
Одно новое оповещение.
2 новых оповещения.
5 новых оповещений.
51 новое оповещение.
And this is exactly what I expect to be the result of ungettext.
But the output is different when the same compiled translation file (django.mo) is used in a Django project.
With django.utils.translation.ungettext it changes to this:
Одно новое оповещение.
2 новое оповещение.
5 новых оповещения.
Одно новое оповещение.
It obviously means that in this case the forms (msgstr) are read correctly, but Plural-Forms is ignored (i.e. the regular scheme for Russian language is used instead of what I have defined).