Commit be170060 by Ned Batchelder

Use strftime_localized for dates.

parent 64db0e78
...@@ -13,9 +13,12 @@ def get_default_time_display(dtime): ...@@ -13,9 +13,12 @@ def get_default_time_display(dtime):
""" """
Converts a datetime to a string representation. This is the default Converts a datetime to a string representation. This is the default
representation used in Studio and LMS. representation used in Studio and LMS.
It is of the form "Apr 09, 2013 at 16:00 UTC".
It will use the "DATE_TIME" format in the current language, if provided,
or defaults to "Apr 09, 2013 at 16:00 UTC".
If None is passed in for dt, an empty string will be returned. If None is passed in for dt, an empty string will be returned.
""" """
if dtime is None: if dtime is None:
return u"" return u""
...@@ -26,8 +29,9 @@ def get_default_time_display(dtime): ...@@ -26,8 +29,9 @@ def get_default_time_display(dtime):
timezone = dtime.strftime('%z') timezone = dtime.strftime('%z')
else: else:
timezone = u" UTC" timezone = u" UTC"
return unicode(dtime.strftime(u"%b %d, %Y at %H:%M{tz}")).format(
tz=timezone).strip() localized = strftime_localized(dtime, "DATE_TIME")
return (localized + timezone).strip()
def get_time_display(dtime, format_string=None, coerce_tz=None): def get_time_display(dtime, format_string=None, coerce_tz=None):
...@@ -53,7 +57,7 @@ def get_time_display(dtime, format_string=None, coerce_tz=None): ...@@ -53,7 +57,7 @@ def get_time_display(dtime, format_string=None, coerce_tz=None):
if dtime is None or format_string is None: if dtime is None or format_string is None:
return get_default_time_display(dtime) return get_default_time_display(dtime)
try: try:
return unicode(dtime.strftime(format_string)) return unicode(strftime_localized(dtime, format_string))
except ValueError: except ValueError:
return get_default_time_display(dtime) return get_default_time_display(dtime)
...@@ -363,3 +367,7 @@ MONTHS = { ...@@ -363,3 +367,7 @@ MONTHS = {
# date-time formats. See http://strftime.org for details. # date-time formats. See http://strftime.org for details.
12: pgettext('month name', 'December'), 12: pgettext('month name', 'December'),
} }
# Now that we are done defining constants, we have to restore the real pgettext
# so that the functions in this module will have the right definition.
pgettext = real_pgettext
...@@ -23,7 +23,9 @@ generates output conf/locale/$DUMMY_LOCALE/LC_MESSAGES, ...@@ -23,7 +23,9 @@ generates output conf/locale/$DUMMY_LOCALE/LC_MESSAGES,
where $DUMMY_LOCALE is the dummy_locale value set in the i18n config where $DUMMY_LOCALE is the dummy_locale value set in the i18n config
""" """
import re
import sys import sys
import polib import polib
from path import path from path import path
...@@ -173,6 +175,10 @@ def make_dummy(filename, locale, converter): ...@@ -173,6 +175,10 @@ def make_dummy(filename, locale, converter):
raise IOError('File does not exist: %r' % filename) raise IOError('File does not exist: %r' % filename)
pofile = polib.pofile(filename) pofile = polib.pofile(filename)
for msg in pofile: for msg in pofile:
# Some strings are actually formatting strings, don't dummy-ify them,
# or dates will look like "DÀTÉ_TÌMÉ_FÖRMÀT Ⱡ'σ# EST"
if re.match(r"^[A-Z_]+_FORMAT$", msg.msgid):
continue
converter.convert_msg(msg) converter.convert_msg(msg)
# Apply declaration for English pluralization rules so that ngettext will # Apply declaration for English pluralization rules so that ngettext will
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment