Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #14570 -- Added new date format character for alternative month…

… names using the new context capabilities. Also add context to Associated Press style month names (refs #9988). Thanks to Claude and shell_dweller.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14899 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7292af85422980df3fefcd0ce131f8a37fe466e9 1 parent dc8c4f0
@jezdez jezdez authored
View
8 django/utils/dateformat.py
@@ -14,12 +14,12 @@
import re
import time
import calendar
-from django.utils.dates import MONTHS, MONTHS_3, MONTHS_AP, WEEKDAYS, WEEKDAYS_ABBR
+from django.utils.dates import MONTHS, MONTHS_3, MONTHS_ALT, MONTHS_AP, WEEKDAYS, WEEKDAYS_ABBR
from django.utils.tzinfo import LocalTimezone
from django.utils.translation import ugettext as _
from django.utils.encoding import force_unicode
-re_formatchars = re.compile(r'(?<!\\)([aAbBcdDfFgGhHiIjlLmMnNOPrsStTUuwWyYzZ])')
+re_formatchars = re.compile(r'(?<!\\)([aAbBcdDEfFgGhHiIjlLmMnNOPrsStTUuwWyYzZ])')
re_escaped = re.compile(r'\\(.)')
class Formatter(object):
@@ -138,6 +138,10 @@ def D(self):
"Day of the week, textual, 3 letters; e.g. 'Fri'"
return WEEKDAYS_ABBR[self.data.weekday()]
+ def E(self):
+ "Alternative month names as required by some locales. Proprietary extension."
+ return MONTHS_ALT[self.data.month]
+
def F(self):
"Month, textual, long; e.g. 'January'"
return MONTHS[self.data.month]
View
16 django/utils/dates.py
@@ -1,6 +1,6 @@
"Commonly-used date structures"
-from django.utils.translation import ugettext_lazy as _
+from django.utils.translation import ugettext_lazy as _, pgettext_lazy
WEEKDAYS = {
0:_('Monday'), 1:_('Tuesday'), 2:_('Wednesday'), 3:_('Thursday'), 4:_('Friday'),
@@ -31,3 +31,17 @@
1:_('Jan.'), 2:_('Feb.'), 3:_('March'), 4:_('April'), 5:_('May'), 6:_('June'), 7:_('July'),
8:_('Aug.'), 9:_('Sept.'), 10:_('Oct.'), 11:_('Nov.'), 12:_('Dec.')
}
+MONTHS_ALT = { # required for long date representation by some locales
+ 1: pgettext_lazy('alt. month', 'January'),
+ 2: pgettext_lazy('alt. month', 'February'),
+ 3: pgettext_lazy('alt. month', 'March'),
+ 4: pgettext_lazy('alt. month', 'April'),
+ 5: pgettext_lazy('alt. month', 'May'),
+ 6: pgettext_lazy('alt. month', 'June'),
+ 7: pgettext_lazy('alt. month', 'July'),
+ 8: pgettext_lazy('alt. month', 'August'),
+ 9: pgettext_lazy('alt. month', 'September'),
+ 10: pgettext_lazy('alt. month', 'October'),
+ 11: pgettext_lazy('alt. month', 'November'),
+ 12: pgettext_lazy('alt. month', 'December')
+}
View
3  docs/ref/templates/builtins.txt
@@ -1175,6 +1175,9 @@ Available format strings:
f Time, in 12-hour hours and minutes, ``'1'``, ``'1:30'``
with minutes left off if they're zero.
Proprietary extension.
+ E Month, locale specific alternative
+ representation usually used for long
+ date representation. ``'listopada'`` (for Polish locale, as opposed to ``'Listopad'``)
F Month, textual, long. ``'January'``
g Hour, 12-hour format without leading ``'1'`` to ``'12'``
zeros.
Please sign in to comment.
Something went wrong with that request. Please try again.