Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#24515 closed Bug (fixed)

Plural handling broken

Reported by: Claude Paroz Owned by: nobody
Component: Internationalization Version: 1.8rc1
Severity: Release blocker Keywords:
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

Translation of plural strings is currently not following the plural equation from the po files and enforce the English default equation.

  • tests/i18n/tests.py

    Test case:diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py
    index ad23861..65aedc0 100644
    a b from django.utils.translation import ( 
    3030    get_language, get_language_from_request, get_language_info, gettext,
    3131    gettext_lazy, ngettext_lazy, npgettext, npgettext_lazy, pgettext,
    3232    pgettext_lazy, string_concat, to_locale, trans_real, ugettext,
    33     ugettext_lazy, ungettext_lazy,
     33    ugettext_lazy, ungettext, ungettext_lazy,
    3434)
    3535
    3636from .forms import CompanyForm, I18nForm, SelectDateForm
    def patch_formats(lang, **settings): 
    5757
    5858class TranslationTests(TestCase):
    5959
     60    @translation.override('fr')
     61    def test_plural(self):
     62        """
     63        Test plurals with ungettext. French differs from English in that 0 is singular.
     64        """
     65        self.assertEqual(ungettext("%d year", "%d years", 0) % 0, "0 année")
     66        self.assertEqual(ungettext("%d year", "%d years", 2) % 2, "2 années")
     67        self.assertEqual(ungettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0}, "0 octet")
     68        self.assertEqual(ungettext("%(size)d byte", "%(size)d bytes", 2) % {'size': 2}, "2 octets")
     69
    6070    def test_override(self):
    6171        activate('de')
    6272        try:

Change History (4)

comment:2 Changed 3 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

comment:3 Changed 3 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: newclosed

In 9e83f30:

Fixed #24515 -- Fixed DjangoTranslation plural handling

comment:4 Changed 3 years ago by Claude Paroz <claude@…>

In 8e4b0d6:

[1.8.x] Fixed #24515 -- Fixed DjangoTranslation plural handling

Backport of 9e83f30cd31 from master.

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