[Django] #21650: Usage example in i18n docs is bad advice for plurals

26 views
Skip to first unread message

Django

unread,
Dec 22, 2013, 10:14:33 AM12/22/13
to django-...@googlegroups.com
#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.

Django

unread,
Dec 22, 2013, 3:52:48 PM12/22/13
to django-...@googlegroups.com
#21650: Usage example in i18n docs is bad advice for plurals
--------------------------------------+------------------------------------
Reporter: nedbatchelder | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by claudep):

* needs_better_patch: => 0
* needs_docs: => 0
* type: Uncategorized => Cleanup/optimization
* needs_tests: => 0
* stage: Unreviewed => Accepted


Comment:

+1, the `count == 1` (and more generally the `verbose_name_plural`
concept, see also #11688) is totally English-centered.

--
Ticket URL: <https://code.djangoproject.com/ticket/21650#comment:1>

Django

unread,
Dec 22, 2013, 7:22:15 PM12/22/13
to django-...@googlegroups.com
#21650: Usage example in i18n docs is bad advice for plurals
--------------------------------------+------------------------------------
Reporter: nedbatchelder | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by nedbatchelder):

Just to clarify: this ticket is merely about the example in the docs.
While the issue in #11688 is true (models' support for singular and plural
is English-centric and simplistic), all I'm pointing out here is that the
i18n docs could at least not fall into the same trap and suggest a
comparison to 1 as the correct way to support plurals.

--
Ticket URL: <https://code.djangoproject.com/ticket/21650#comment:2>

Django

unread,
Dec 23, 2013, 3:51:07 AM12/23/13
to django-...@googlegroups.com
#21650: Usage example in i18n docs is bad advice for plurals
--------------------------------------+------------------------------------
Reporter: nedbatchelder | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by claudep):

I suggest to simply remove that example in the docs, because if we remove
the verbose_name/plural stuff in it, it doesn't bring anything new to the
discussion compared to the previous example. Opinion?

--
Ticket URL: <https://code.djangoproject.com/ticket/21650#comment:3>

Django

unread,
Dec 23, 2013, 5:54:44 AM12/23/13
to django-...@googlegroups.com
#21650: Usage example in i18n docs is bad advice for plurals
--------------------------------------+------------------------------------
Reporter: nedbatchelder | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by nedbatchelder):

My one counter to that might be: Change this example to an explanation of
why it isn't a good idea:

{{{
Note that pluralization is complicated, and works differently in other
languages.
Comparing count to 1 isn't always the correct rule. This code looks
sophisticated,
but will produce the wrong results for other languages:

....

Don't try to implement your own singular-or-plural logic, it won't be
correct.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21650#comment:4>

Django

unread,
Dec 26, 2013, 12:59:44 PM12/26/13
to django-...@googlegroups.com
#21650: Usage example in i18n docs is bad advice for plurals
--------------------------------------+------------------------------------
Reporter: nedbatchelder | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Old description:

New description:

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

--

Comment (by timo):

I don't use i18n, but Ned's suggest seems reasonable to me. Claude, what
do you think? My only question would be what modifications to make to the
note that follows. Currently it says, "When using this technique", and my
understanding is that we'd be changing things to say not to use this
technique. I think the note still has value though as it's linked to from
elsewhere.

--
Ticket URL: <https://code.djangoproject.com/ticket/21650#comment:5>

Django

unread,
Dec 26, 2013, 2:32:26 PM12/26/13
to django-...@googlegroups.com
#21650: Usage example in i18n docs is bad advice for plurals
--------------------------------------+------------------------------------
Reporter: nedbatchelder | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by claudep):

Sure, but you know I'm not the most skilled writer for English
documentation. Feel free to go ahead.

--
Ticket URL: <https://code.djangoproject.com/ticket/21650#comment:6>

Django

unread,
Dec 26, 2013, 4:07:15 PM12/26/13
to django-...@googlegroups.com
#21650: Usage example in i18n docs is bad advice for plurals
--------------------------------------+------------------------------------
Reporter: nedbatchelder | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timo):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/21650#comment:7>

Django

unread,
Dec 26, 2013, 5:42:38 PM12/26/13
to django-...@googlegroups.com
#21650: Usage example in i18n docs is bad advice for plurals
--------------------------------------+------------------------------------
Reporter: nedbatchelder | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by claudep):

Thanks, that looks good. However, I'd like to see somewhere the `%(name)s
object`/`%(name)s objects` trick that Ned suggested. Even if it might
produce suboptimal strings in English, it's often the only proper way to
handle i18n in a right manner.

--
Ticket URL: <https://code.djangoproject.com/ticket/21650#comment:8>

Django

unread,
Dec 27, 2013, 3:31:41 AM12/27/13
to django-...@googlegroups.com
#21650: Usage example in i18n docs is bad advice for plurals
--------------------------------------+------------------------------------
Reporter: nedbatchelder | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by claudep):

Fine for me. Ned?

--
Ticket URL: <https://code.djangoproject.com/ticket/21650#comment:9>

Django

unread,
Dec 27, 2013, 7:07:33 AM12/27/13
to django-...@googlegroups.com
#21650: Usage example in i18n docs is bad advice for plurals
--------------------------------------+------------------------------------
Reporter: nedbatchelder | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.6

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by nedbatchelder):

Looks great, thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/21650#comment:10>

Django

unread,
Dec 27, 2013, 10:02:44 AM12/27/13
to django-...@googlegroups.com
#21650: Usage example in i18n docs is bad advice for plurals
--------------------------------------+------------------------------------
Reporter: nedbatchelder | Owner: nobody
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.6
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"85270ef3f5bf96b556e697bc5a46bf925ec4be21"]:
{{{
#!CommitTicketReference repository=""
revision="85270ef3f5bf96b556e697bc5a46bf925ec4be21"
Fixed #21650 -- Corrected bad advice for plural translation.

Thanks nedbatchelder and claudep.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21650#comment:11>

Django

unread,
Dec 27, 2013, 10:03:02 AM12/27/13
to django-...@googlegroups.com
#21650: Usage example in i18n docs is bad advice for plurals
--------------------------------------+------------------------------------
Reporter: nedbatchelder | Owner: nobody
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.6

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"3b79fbabcdfefa6c5734a9645be4ffee02e4a270"]:
{{{
#!CommitTicketReference repository=""
revision="3b79fbabcdfefa6c5734a9645be4ffee02e4a270"
[1.6.x] Fixed #21650 -- Corrected bad advice for plural translation.

Thanks nedbatchelder and claudep.

Backport of 85270ef3f5 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21650#comment:12>

Reply all
Reply to author
Forward
0 new messages