浏览代码

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.
Tzu-ping Chung 7 年之前
父节点
当前提交
85e6a1c634

二进制
django/contrib/humanize/locale/fr/LC_MESSAGES/django.mo


+ 42 - 10
django/contrib/humanize/locale/fr/LC_MESSAGES/django.po

@@ -10,8 +10,8 @@ msgstr ""
 "Project-Id-Version: django\n"
 "Report-Msgid-Bugs-To: \n"
 "POT-Creation-Date: 2015-01-17 11:07+0100\n"
-"PO-Revision-Date: 2017-09-19 16:40+0000\n"
-"Last-Translator: Jannis Leidel <jannis@leidel.info>\n"
+"PO-Revision-Date: 2017-12-06 01:44+0800\n"
+"Last-Translator: Tzu-ping Chung <uranusjr@gmail.com>\n"
 "Language-Team: French (http://www.transifex.com/django/django/language/fr/)\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=UTF-8\n"
@@ -22,17 +22,49 @@ msgstr ""
 msgid "Humanize"
 msgstr "Humanisation"
 
-msgid "th"
-msgstr "<sup>e</sup>"
+msgctxt "ordinal 11, 12, 13"
+msgid "{}th"
+msgstr "{}<sup>e</sup>"
 
-msgid "st"
-msgstr "<sup>er</sup>"
+msgctxt "ordinal 0"
+msgid "{}th"
+msgstr "{}<sup>e</sup>"
 
-msgid "nd"
-msgstr "<sup>e</sup>"
+msgctxt "ordinal 1"
+msgid "{}st"
+msgstr "{}<sup>er</sup>"
 
-msgid "rd"
-msgstr "<sup>e</sup>"
+msgctxt "ordinal 2"
+msgid "{}nd"
+msgstr "{}<sup>e</sup>"
+
+msgctxt "ordinal 3"
+msgid "{}rd"
+msgstr "{}<sup>e</sup>"
+
+msgctxt "ordinal 4"
+msgid "{}th"
+msgstr "{}<sup>e</sup>"
+
+msgctxt "ordinal 5"
+msgid "{}th"
+msgstr "{}<sup>e</sup>"
+
+msgctxt "ordinal 6"
+msgid "{}th"
+msgstr "{}<sup>e</sup>"
+
+msgctxt "ordinal 7"
+msgid "{}th"
+msgstr "{}<sup>e</sup>"
+
+msgctxt "ordinal 8"
+msgid "{}th"
+msgstr "{}<sup>e</sup>"
+
+msgctxt "ordinal 9"
+msgid "{}th"
+msgstr "{}<sup>e</sup>"
 
 #, python-format
 msgid "%(value).1f million"

+ 28 - 4
django/contrib/humanize/templatetags/humanize.py

@@ -23,11 +23,35 @@ def ordinal(value):
         value = int(value)
     except (TypeError, ValueError):
         return value
-    suffixes = (_('th'), _('st'), _('nd'), _('rd'), _('th'), _('th'), _('th'), _('th'), _('th'), _('th'))
-    if value % 100 in (11, 12, 13):  # special case
-        return mark_safe("%d%s" % (value, suffixes[0]))
+    if 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:
+        templates = (
+            # Translators: Ordinal format when value ends with 0, e.g. 80th.
+            pgettext('ordinal 0', '{}th'),
+            # Translators: Ordinal format when value ends with 1, e.g. 81st, except 11.
+            pgettext('ordinal 1', '{}st'),
+            # Translators: Ordinal format when value ends with 2, e.g. 82nd, except 12.
+            pgettext('ordinal 2', '{}nd'),
+            # Translators: Ordinal format when value ends with 3, e.g. 83th, except 13.
+            pgettext('ordinal 3', '{}rd'),
+            # Translators: Ordinal format when value ends with 4, e.g. 84th.
+            pgettext('ordinal 4', '{}th'),
+            # Translators: Ordinal format when value ends with 5, e.g. 85th.
+            pgettext('ordinal 5', '{}th'),
+            # Translators: Ordinal format when value ends with 6, e.g. 86th.
+            pgettext('ordinal 6', '{}th'),
+            # Translators: Ordinal format when value ends with 7, e.g. 87th.
+            pgettext('ordinal 7', '{}th'),
+            # Translators: Ordinal format when value ends with 8, e.g. 88th.
+            pgettext('ordinal 8', '{}th'),
+            # Translators: Ordinal format when value ends with 9, e.g. 89th.
+            pgettext('ordinal 9', '{}th'),
+        )
+        value = templates[value % 10].format(value)
     # Mark value safe so i18n does not break with <sup> or <sub> see #19988
-    return mark_safe("%d%s" % (value, suffixes[value % 10]))
+    return mark_safe(value)
 
 
 @register.filter(is_safe=True)