1
# Copyright (C) 2009-2011 by the Free Software Foundation, Inc.
3
# This file is part of GNU Mailman.
5
# GNU Mailman is free software: you can redistribute it and/or modify it under
6
# the terms of the GNU General Public License as published by the Free
7
# Software Foundation, either version 3 of the License, or (at your option)
10
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15
# You should have received a copy of the GNU General Public License along with
16
# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18
"""Internationalization."""
20
from __future__ import absolute_import, unicode_literals
31
from flufl.i18n import PackageStrategy, registry
33
#import mailman.messages
40
def initialize(application=None):
41
"""Initialize the i18n subsystem.
43
:param application: An optional `flufl.i18n.Application` instance to use
44
as the translation context. This primarily exists to support the
46
:type application: `flufl.i18n.Application`
49
if application is None:
50
print 'problem in i18n initialize'
51
# strategy = PackageStrategy('mailman', mailman.messages)
52
# application = registry.register(strategy)
61
:param date: The date to translate.
62
:type date: str or time float
63
:return: The translated date.
66
# Don't make these module globals since we have to do runtime translation
67
# of the strings anyway.
69
_('Mon'), _('Tue'), _('Wed'), _('Thu'),
70
_('Fri'), _('Sat'), _('Sun')
74
_('Jan'), _('Feb'), _('Mar'), _('Apr'), _('May'), _('Jun'),
75
_('Jul'), _('Aug'), _('Sep'), _('Oct'), _('Nov'), _('Dec')
78
# pylint: disable-msg=W0612
79
tzname = _('Server Local Time')
80
if isinstance(date, str):
82
year, mon, day, hh, mm, ss, wday, ydat, dst = time.strptime(date)
84
tzname = time.tzname[dst]
86
# MAS: No exception but dst = -1 so try
87
return ctime(time.mktime((year, mon, day, hh, mm, ss, wday,
89
except (ValueError, AttributeError):
91
wday, mon, day, hms, year = date.split()
92
hh, mm, ss = hms.split(':')
101
for i in range(0, 7):
102
wconst = (1999, 1, 1, 0, 0, 0, i, 1, 0)
103
if wday.lower() == time.strftime('%a', wconst).lower():
106
for i in range(1, 13):
107
mconst = (1999, i, 1, 0, 0, 0, 0, 1, 0)
108
if mon.lower() == time.strftime('%b', mconst).lower():
112
# pylint: disable-msg=W0612
113
year, mon, day, hh, mm, ss, wday, yday, dst = time.localtime(date)
115
tzname = time.tzname[dst]
117
wday = daysofweek[wday]
119
return _('$wday $mon $day $hh:$mm:$ss $tzname $year')