Opened 10 years ago

Last modified 10 years ago

#21650 closed Cleanup/optimization

Usage example in i18n docs is bad advice for plurals — at Initial Version

Reported by: Ned Batchelder Owned by: nobody
Component: Documentation Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This example in the i18n docs:

Lets see a slightly more complex usage example::

    from django.utils.translation import ungettext
    from myapp.models import Report

    count = Report.objects.count()
    if count == 1:
        name = Report._meta.verbose_name
    else:
        name = Report._meta.verbose_name_plural

    text = ungettext(
            'There is %(count)d %(name)s available.',
            'There are %(count)d %(name)s available.',
            count
    ) % {
        'count': count,
        'name': name
    }

Here we choose between two forms of name (singular and plural) based on whether the count is 1 or not. That is the rule in English, but not in other languages. The whole point of ungettext is to defer the logic that performs the mapping from number to text, since it depends on the language.

Unfortunately, I think the only solution is to use more stilted language:

text = ungettext(
    'There is %(count)d %(name)s object available.',
    'There are %(count)d %(name)s objects available.',
    count
) % {
    'count': count,
    'name': Report._meta.verbose_name,
}

and ignore the verbose_name_plural altogether.

Change History (0)

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