Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#23520 closed Cleanup/optimization (fixed)

Custom Plural-Forms is ignored in django.po

Reported by: aruseni Owned by: nobody
Component: Documentation Version: dev
Severity: Normal Keywords: gettext, plural-forms
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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).

Change History (8)

comment:1 by Claude Paroz, 10 years ago

Clearly, Django doesn't support different plural forms per file, and I don't think that this is going to change (all catalogs are merged).
Is there a good place where this could be documented?

comment:2 by aruseni, 10 years ago

I see. Thank you!

Probably it could be documented here:

https://docs.djangoproject.com/en/dev/topics/i18n/translation/#pluralization

comment:3 by Claude Paroz, 10 years ago

Component: InternationalizationDocumentation
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization
Version: 1.7master

comment:5 by Tim Graham, 9 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Claude Paroz <claude@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 556eb67:

Fixed #23520 -- Explained that custom plural forms should be avoided

Thanks aruseni for the report.

comment:7 by Claude Paroz <claude@…>, 9 years ago

In 5da3153:

[1.8.x] Fixed #23520 -- Explained that custom plural forms should be avoided

Thanks aruseni for the report.
Backport of 556eb67701 from master.

comment:8 by Claude Paroz <claude@…>, 9 years ago

In 5cad259:

[1.7.x] Fixed #23520 -- Explained that custom plural forms should be avoided

Thanks aruseni for the report.
Backport of 556eb67701 from master.

Note: See TracTickets for help on using tickets.
Back to Top