[Django] #28877: Improve humanize’s |ordinal formatting

21 views
Skip to first unread message

Django

unread,
Dec 3, 2017, 1:03:13 AM12/3/17
to django-...@googlegroups.com
#28877: Improve humanize’s |ordinal formatting
--------------------------------------------+------------------------
Reporter: Tzu-ping Chung | Owner: nobody
Type: New feature | Status: new
Component: contrib.humanize | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
There are languages, e.g. Chinese, that do not use suffix, but prefix to
indicate ordinals. The current implementation means that it is impossible
to translate the suffixes to work with those languages. I understand this
has its root in a much larger issue (#15156), but this can be fixed very
trivially by including the whole format instead of just the suffix,
something like:


{{{
@register.filter(is_safe=True)
def ordinal(value):
"""
Convert an integer to its ordinal as a string. 1 is '1st', 2 is '2nd',
3 is '3rd', etc. Works for any integer.
"""
try:
value = int(value)
except (TypeError, ValueError):
return value
formats = (_('%dth'), _('%dst'), _('%dnd'), _('%drd'), _('%dth'),
_('%dth'), _('%dth'), _('%dth'), _('%dth'), _('%dth'))
if value % 100 in (11, 12, 13): # special case
return mark_safe(formats[0] % (value,))
return mark_safe(formats[value % 10] % (value,))
}}}


I can submit a pull request if this is considered reasonable.

--
Ticket URL: <https://code.djangoproject.com/ticket/28877>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 4, 2017, 2:34:21 PM12/4/17
to django-...@googlegroups.com
#28877: Improve humanize’s |ordinal formatting
----------------------------------+------------------------------------

Reporter: Tzu-ping Chung | Owner: nobody
Type: New feature | Status: new
Component: contrib.humanize | Version: master
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 Claude Paroz):

* stage: Unreviewed => Accepted


Comment:

Pull request welcome!

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

Django

unread,
Dec 4, 2017, 11:57:03 PM12/4/17
to django-...@googlegroups.com
#28877: Improve humanize’s |ordinal formatting
-------------------------------------+-------------------------------------
Reporter: Tzu-ping Chung | Owner: Tzu-ping
| Chung
Type: New feature | Status: assigned
Component: contrib.humanize | Version: master

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 Tzu-ping Chung):

* owner: nobody => Tzu-ping Chung
* status: new => assigned
* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/9422 PR]

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

Django

unread,
Dec 5, 2017, 10:54:43 AM12/5/17
to django-...@googlegroups.com
#28877: Improve humanize’s |ordinal formatting
-------------------------------------+-------------------------------------
Reporter: Tzu-ping Chung | Owner: Tzu-ping
| Chung
Type: New feature | Status: assigned
Component: contrib.humanize | Version: master

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

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

* needs_better_patch: 0 => 1


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

Django

unread,
Dec 5, 2017, 3:41:49 PM12/5/17
to django-...@googlegroups.com
#28877: Improve humanize’s |ordinal formatting
-------------------------------------+-------------------------------------
Reporter: Tzu-ping Chung | Owner: Tzu-ping
| Chung
Type: New feature | Status: assigned
Component: contrib.humanize | Version: master

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 Claude Paroz):

* needs_better_patch: 1 => 0


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

Django

unread,
Dec 6, 2017, 10:20:44 AM12/6/17
to django-...@googlegroups.com
#28877: Improve translation flexibility of ordinal template tag results

-------------------------------------+-------------------------------------
Reporter: Tzu-ping Chung | Owner: Tzu-ping
Type: | Chung
Cleanup/optimization | Status: assigned
Component: contrib.humanize | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Accepted => Ready for checkin
* type: New feature => Cleanup/optimization


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

Django

unread,
Dec 6, 2017, 10:21:13 AM12/6/17
to django-...@googlegroups.com
#28877: Improve translation flexibility of ordinal template tag results
-------------------------------------+-------------------------------------
Reporter: Tzu-ping Chung | Owner: Tzu-ping
Type: | Chung
Cleanup/optimization | Status: closed
Component: contrib.humanize | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
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: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"85e6a1c634fed55c43090e37b802c721d9e7eaaa" 85e6a1c6]:
{{{
#!CommitTicketReference repository=""
revision="85e6a1c634fed55c43090e37b802c721d9e7eaaa"
Fixed #28877 -- Made ordinal template filter results more localizable.

Marked the whole pattern (e.g. "{value}th") as translatable, instead of
just this suffix, so that languages not using suffixes for ordinals can
use this tag.
}}}

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

Django

unread,
Mar 6, 2026, 7:02:30 AM (22 hours ago) Mar 6
to django-...@googlegroups.com
#28877: Improve translation flexibility of ordinal template tag results
-------------------------------------+-------------------------------------
Reporter: Tzu-ping Chung | Owner: Tzu-ping
Type: | Chung
Cleanup/optimization | Status: closed
Component: contrib.humanize | Version: dev
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by nessita <124304+nessita@…>):

In [changeset:"9adc205b6d0269a81ce93a7e6d6b0f375f6bd526" 9adc205]:
{{{#!CommitTicketReference repository=""
revision="9adc205b6d0269a81ce93a7e6d6b0f375f6bd526"
Refs #28877 -- Added special ordinal context when humanizing value 1.

Some languages use a different ordinal suffix for the number 1 than
for other values ending in 1 (e.g. 21, 31). Added a dedicated
pgettext context "ordinal is 1" to allow translators to handle
this distinction.

For example, in French, 1 is written as "1er" while 21, 31, etc. use
"21e", "31e", etc.

Co-authored-by: Natalia <124304+...@users.noreply.github.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28877#comment:7>
Reply all
Reply to author
Forward
0 new messages