#21650: Usage example in i18n docs is bad advice for plurals
-------------------------------+--------------------
Reporter: nedbatchelder | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/21650>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/056.a19d424f4c95c39d106cc53e222cf16d%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.