Ticket #14570: alternative-long-date-format.diff

File alternative-long-date-format.diff, 3.3 KB (added by shell_dweller, 14 years ago)

A better patch based on pgettext

  • django/utils/dates.py

     
    11"Commonly-used date structures"
    22
    3 from django.utils.translation import ugettext_lazy as _
     3from django.utils.translation import ugettext_lazy as _, pgettext_lazy
    44
    55WEEKDAYS = {
    66    0:_('Monday'), 1:_('Tuesday'), 2:_('Wednesday'), 3:_('Thursday'), 4:_('Friday'),
     
    3131    1:_('Jan.'), 2:_('Feb.'), 3:_('March'), 4:_('April'), 5:_('May'), 6:_('June'), 7:_('July'),
    3232    8:_('Aug.'), 9:_('Sept.'), 10:_('Oct.'), 11:_('Nov.'), 12:_('Dec.')
    3333}
     34MONTHS_ALTERNATIVE = { # required for long date representation by some locales
     35    1:pgettext_lazy('alt. month', 'January'), 2:pgettext_lazy('alt. month', 'February'),
     36    3:pgettext_lazy('alt. month', 'March'), 4:pgettext_lazy('alt. month', 'April'),
     37    5:pgettext_lazy('alt. month', 'May'), 6:pgettext_lazy('alt. month', 'June'),
     38    7:pgettext_lazy('alt. month', 'July'), 8:pgettext_lazy('alt. month', 'August'),
     39    9:pgettext_lazy('alt. month', 'September'), 10:pgettext_lazy('alt. month', 'October'),
     40    11:pgettext_lazy('alt. month', 'November'), 12:pgettext_lazy('alt. month', 'December')
     41}
     42 No newline at end of file
  • django/utils/dateformat.py

     
    1414import re
    1515import time
    1616import calendar
    17 from django.utils.dates import MONTHS, MONTHS_3, MONTHS_AP, WEEKDAYS, WEEKDAYS_ABBR
     17from django.utils.dates import MONTHS, MONTHS_3, MONTHS_AP, WEEKDAYS, WEEKDAYS_ABBR, MONTHS_ALTERNATIVE
    1818from django.utils.tzinfo import LocalTimezone
    1919from django.utils.translation import ugettext as _
    2020from django.utils.encoding import force_unicode
    2121
    22 re_formatchars = re.compile(r'(?<!\\)([aAbBcdDfFgGhHiIjlLmMnNOPrsStTUuwWyYzZ])')
     22re_formatchars = re.compile(r'(?<!\\)([aAbBcdDEfFgGhHiIjlLmMnNOPrsStTUuwWyYzZ])')
    2323re_escaped = re.compile(r'\\(.)')
    2424
    2525class Formatter(object):
     
    138138        "Day of the week, textual, 3 letters; e.g. 'Fri'"
    139139        return WEEKDAYS_ABBR[self.data.weekday()]
    140140
     141    def E(self):
     142        "Alternative month names as required by some locales"
     143        return MONTHS_ALTERNATIVE[self.data.month]
     144
    141145    def F(self):
    142146        "Month, textual, long; e.g. 'January'"
    143147        return MONTHS[self.data.month]
  • docs/ref/templates/builtins.txt

     
    11131113    f                 Time, in 12-hour hours and minutes,       ``'1'``, ``'1:30'``
    11141114                      with minutes left off if they're zero.
    11151115                      Proprietary extension.
     1116    E                 Month, locale specific alternative
     1117                      representation usually used for long
     1118                      date representation.                      ``'listopada'`` (for Polish locale, as opposed to ``'Listopad'``)
    11161119    F                 Month, textual, long.                     ``'January'``
    11171120    g                 Hour, 12-hour format without leading      ``'1'`` to ``'12'``
    11181121                      zeros.
Back to Top