Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Jannis Leidel authored
8  django/utils/dateformat.py
@@ -14,12 +14,12 @@
14 14
 import re
15 15
 import time
16 16
 import calendar
17  
-from django.utils.dates import MONTHS, MONTHS_3, MONTHS_AP, WEEKDAYS, WEEKDAYS_ABBR
  17
+from django.utils.dates import MONTHS, MONTHS_3, MONTHS_ALT, MONTHS_AP, WEEKDAYS, WEEKDAYS_ABBR
18 18
 from django.utils.tzinfo import LocalTimezone
19 19
 from django.utils.translation import ugettext as _
20 20
 from django.utils.encoding import force_unicode
21 21
 
22  
-re_formatchars = re.compile(r'(?<!\\)([aAbBcdDfFgGhHiIjlLmMnNOPrsStTUuwWyYzZ])')
  22
+re_formatchars = re.compile(r'(?<!\\)([aAbBcdDEfFgGhHiIjlLmMnNOPrsStTUuwWyYzZ])')
23 23
 re_escaped = re.compile(r'\\(.)')
24 24
 
25 25
 class Formatter(object):
@@ -138,6 +138,10 @@ def D(self):
138 138
         "Day of the week, textual, 3 letters; e.g. 'Fri'"
139 139
         return WEEKDAYS_ABBR[self.data.weekday()]
140 140
 
  141
+    def E(self):
  142
+        "Alternative month names as required by some locales. Proprietary extension."
  143
+        return MONTHS_ALT[self.data.month]
  144
+
141 145
     def F(self):
142 146
         "Month, textual, long; e.g. 'January'"
143 147
         return MONTHS[self.data.month]
16  django/utils/dates.py
... ...
@@ -1,6 +1,6 @@
1 1
 "Commonly-used date structures"
2 2
 
3  
-from django.utils.translation import ugettext_lazy as _
  3
+from django.utils.translation import ugettext_lazy as _, pgettext_lazy
4 4
 
5 5
 WEEKDAYS = {
6 6
     0:_('Monday'), 1:_('Tuesday'), 2:_('Wednesday'), 3:_('Thursday'), 4:_('Friday'),
@@ -31,3 +31,17 @@
31 31
     1:_('Jan.'), 2:_('Feb.'), 3:_('March'), 4:_('April'), 5:_('May'), 6:_('June'), 7:_('July'),
32 32
     8:_('Aug.'), 9:_('Sept.'), 10:_('Oct.'), 11:_('Nov.'), 12:_('Dec.')
33 33
 }
  34
+MONTHS_ALT = { # required for long date representation by some locales
  35
+    1: pgettext_lazy('alt. month', 'January'),
  36
+    2: pgettext_lazy('alt. month', 'February'),
  37
+    3: pgettext_lazy('alt. month', 'March'),
  38
+    4: pgettext_lazy('alt. month', 'April'),
  39
+    5: pgettext_lazy('alt. month', 'May'),
  40
+    6: pgettext_lazy('alt. month', 'June'),
  41
+    7: pgettext_lazy('alt. month', 'July'),
  42
+    8: pgettext_lazy('alt. month', 'August'),
  43
+    9: pgettext_lazy('alt. month', 'September'),
  44
+    10: pgettext_lazy('alt. month', 'October'),
  45
+    11: pgettext_lazy('alt. month', 'November'),
  46
+    12: pgettext_lazy('alt. month', 'December')
  47
+}
3  docs/ref/templates/builtins.txt
@@ -1175,6 +1175,9 @@ Available format strings:
1175 1175
     f                 Time, in 12-hour hours and minutes,       ``'1'``, ``'1:30'``
1176 1176
                       with minutes left off if they're zero.
1177 1177
                       Proprietary extension.
  1178
+    E                 Month, locale specific alternative
  1179
+                      representation usually used for long
  1180
+                      date representation.                      ``'listopada'`` (for Polish locale, as opposed to ``'Listopad'``)
1178 1181
     F                 Month, textual, long.                     ``'January'``
1179 1182
     g                 Hour, 12-hour format without leading      ``'1'`` to ``'12'``
1180 1183
                       zeros.

0 notes on commit 7292af8

Please sign in to comment.
Something went wrong with that request. Please try again.