summaryrefslogtreecommitdiff
path: root/django/contrib/humanize
diff options
context:
space:
mode:
authorJulien Palard <julien@palard.fr>2025-01-15 13:18:06 +0100
committernessita <124304+nessita@users.noreply.github.com>2026-03-06 09:02:20 -0300
commit9adc205b6d0269a81ce93a7e6d6b0f375f6bd526 (patch)
tree280adddad1efcf295792ddef5a11ca5c89bf21fd /django/contrib/humanize
parent23931eb7ff562b44d78859f29ca81d77d212df06 (diff)
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+nessita@users.noreply.github.com>
Diffstat (limited to 'django/contrib/humanize')
-rw-r--r--django/contrib/humanize/templatetags/humanize.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/django/contrib/humanize/templatetags/humanize.py b/django/contrib/humanize/templatetags/humanize.py
index 26a9dd3a3f..79d2e15667 100644
--- a/django/contrib/humanize/templatetags/humanize.py
+++ b/django/contrib/humanize/templatetags/humanize.py
@@ -32,7 +32,10 @@ def ordinal(value):
return value
if value < 0:
return str(value)
- if value % 100 in (11, 12, 13):
+ if value == 1:
+ # Translators: Ordinal format when value is 1 (1st).
+ value = pgettext("ordinal is 1", "{}st").format(value)
+ elif value % 100 in (11, 12, 13):
# Translators: Ordinal format for 11 (11th), 12 (12th), and 13 (13th).
value = pgettext("ordinal 11, 12, 13", "{}th").format(value)
else: