Opened 17 years ago
Closed 14 years ago
#5425 closed (duplicate)
Incorrect plurals in admin pagination template
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | contrib.admin | Version: | |
Severity: | Keywords: | admin, internationalization | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Attachments (3)
Change History (22)
by , 17 years ago
Attachment: | admin-pagination.diff added |
---|
comment:1 by , 17 years ago
comment:2 by , 17 years ago
This won't work for languages with more than one plural form. For example, in Russian "1 object, 2 objects, 10 objects" becomes "1 объект, 2 объекта, 10 объектов". I think, the only way to handle it correctly is to use ungettext
, possibly via {% blocktrans %}
... {% plural %}
... {% endblocktrans %}
template tag.
comment:3 by , 17 years ago
My language (Czech) is similar - it has also two plural forms. Usually I use ungettext - but it is not possible in this situation what is the reason for this ticket.
For pagination template I have to use Meta class from model which has only two relevant attributes - verbose_name and verbose_name_plural. Therefore I can't use ungettext. So I use trick - I know that "2 объектов" (I supposed it is used now) is a mistake, so I "translate" it as "Oбъектов: 2" which is ok (maybe, I don't speak Russian - but it is ok in my language).
There is another solution: Verbose name could be defined as function with ungettext. I tried it and it worked - but it seems to be too complex for this problem. If Django developers tell it is the preferred variant, I will create a patch - it is no problem for me.
comment:4 by , 17 years ago
What if we use something like ungettext(u'%%i %s' % verbose_name, u'%%i %s' % verbose_name_plural, n) % n
? The only problem is how to mark these dynamically created strings for translation. Maybe make-messages.py
could take care of this.
comment:5 by , 17 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:6 by , 17 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Since there are about a million different proposals for handling pagination in templates in various places, I'd like to consolidate it all into #3169 for now (and, more realistically, in discussion on django-developers).
comment:7 by , 17 years ago
Keywords: | internationalization added; templates pagination removed |
---|---|
Resolution: | duplicate |
Status: | closed → reopened |
Summary: | [newforms-admin] - more flexible pagination template → [newforms-admin] - incorrect plurals in admin pagination template |
I don't understand what exactly you propose. I suppose I have this model:
class Object(models.Model): # ... class Meta: verbose_name = _('object') verbose_name_plural = _('object')
If the current code would be in python, it would be something as:
if n == 1: text = '%i %s' % (count, verbose_name) else: text = '%i %s' % (count, verbose_name_plural)
The result is:
- 1 object; 2 objects; 5 objects - ok in English
- 1 objekt; 2 objekty; 10 objekty - not ok in Czech
- 1 объект; 2 объекта; 10 объекта - probably not ok in Russian
I propose this little change:
if n == 1: text = _('%{count}i %{verbose_name}s') % {'count': count, 'verbose_name': verbose_name} else: text = _('%{count}i %{verbose_name_plural}s') % {'count': count, 'verbose_name_plural': verbose_name_plural}
After translation the result would be:
- 1 object; 2 objects; 5 objects - ok in English
- Objekt: 1; Objekty: 2; Objekty: 10 - quite ok in Czech
- Oбъект: 1; Oбъекта: 2; Oбъекта: 10 - maybe quite ok in Russian
I tried another solution:
class Object(models.Model): # ... class Meta: verbose_name = lambda n: ungettext('object', 'objects', n) % {'n' : n}
Then I changed django.db.models.options.Options to check if verbose_name was function. It worked and it was backward-compatible but I think that this problem doesn't deserve such complex solution.
So I try to imagine which patch you propose. Should make-messages.py be smarted? I think it is possible - expressions in models after verbose_name would be considered as pluralized messages. Options class and template would count with it. But is it worth? Is my solution really not good enough for Russian?
comment:8 by , 17 years ago
I reopened the ticket because it is not about pagination - it is about internationalization in a template. It just happened that the name of the template was "pagination.html".
I see I chose bad summary and bad keywords. So I changed it. Now it shouldn't be misguided.
comment:9 by , 17 years ago
Keywords: | nfa-someday added |
---|
Old admin looks to be no different from newforms-admin for this issue, so this should not block merge.
comment:10 by , 17 years ago
I don't like this solution. It's too wordy (admin is only a single example of where you might need pluralisation support in this sort of situation). We need a version of blocktrans that can handle plural specifications somehow, I suspect.
I have a memory that this has been discussed on django-developer in the past and we got a bit stuck on the syntax. I'd rather persist with trying to get that right, though. Somebody who has ideas should start a discussion on django-dev to see if we can get some consensus.
comment:11 by , 15 years ago
Keywords: | nfa-someday removed |
---|---|
Summary: | [newforms-admin] - incorrect plurals in admin pagination template → Incorrect plurals in admin pagination template |
Triage Stage: | Design decision needed → Accepted |
Version: | newforms-admin |
comment:12 by , 14 years ago
Patch needs improvement: | set |
---|
comment:13 by , 14 years ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
We have a blocktrans tag supporting pluralization now. Trivial one-line patch attached, test suite still passes.
by , 14 years ago
Attachment: | fix5425.patch added |
---|
comment:14 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
comment:15 by , 14 years ago
comment:16 by , 14 years ago
comment:17 by , 14 years ago
comment:18 by , 14 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:19 by , 14 years ago
Resolution: | → duplicate |
---|---|
Status: | reopened → closed |
Triage Stage: | Ready for checkin → Accepted |
Closing this as a duplicate of #14844, because that has more discussion about how to correctly fix this.
See http://groups.google.com/group/django-developers/browse_thread/thread/2d8a06071553eafe/1c6587f10052814a#1c6587f10052814a
My language is really strange. Imagine that you have this grammar:
And expression "5 contacts" is an error. OK, everybody knows what it
means - but for perfectionist it is not good enough.
So I propose to enable "translate" this expression in admin. It would
be no change for English and for other languages. But I could use this
translation: