~dushyant37/+junk/Archiver

« back to all changes in this revision

Viewing changes to Archiver/core/i18n.py

  • Committer: Dushyant Bansal
  • Date: 2011-10-06 13:28:44 UTC
  • Revision ID: dushyant37@gmail.com-20111006132844-m2c0co7mnh0vcrfw
Making it easy to install using setup.py install

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009-2011 by the Free Software Foundation, Inc.
2
 
#
3
 
# This file is part of GNU Mailman.
4
 
#
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)
8
 
# any later version.
9
 
#
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
13
 
# more details.
14
 
#
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/>.
17
 
 
18
 
"""Internationalization."""
19
 
 
20
 
from __future__ import absolute_import, unicode_literals
21
 
 
22
 
__metaclass__ = type
23
 
__all__ = [
24
 
    '_',
25
 
    'ctime',
26
 
    'initialize',
27
 
    ]
28
 
 
29
 
 
30
 
import time
31
 
from flufl.i18n import PackageStrategy, registry
32
 
 
33
 
#import mailman.messages
34
 
 
35
 
 
36
 
_ = None
37
 
 
38
 
 
39
 
 
40
 
def initialize(application=None):
41
 
    """Initialize the i18n subsystem.
42
 
 
43
 
    :param application: An optional `flufl.i18n.Application` instance to use
44
 
        as the translation context.  This primarily exists to support the
45
 
        testing environment.
46
 
    :type application: `flufl.i18n.Application`
47
 
    """
48
 
    global _
49
 
    if application is None:
50
 
        print 'problem in i18n initialize'
51
 
#        strategy = PackageStrategy('mailman', mailman.messages)
52
 
#        application = registry.register(strategy)
53
 
    _ = application._
54
 
    print id(_)
55
 
 
56
 
 
57
 
 
58
 
def ctime(date):
59
 
    """Translate a ctime.
60
 
 
61
 
    :param date: The date to translate.
62
 
    :type date: str or time float
63
 
    :return: The translated date.
64
 
    :rtype: string
65
 
    """
66
 
    # Don't make these module globals since we have to do runtime translation
67
 
    # of the strings anyway.
68
 
    daysofweek = [
69
 
        _('Mon'), _('Tue'), _('Wed'), _('Thu'),
70
 
        _('Fri'), _('Sat'), _('Sun')
71
 
        ]
72
 
    months = [
73
 
        '',
74
 
        _('Jan'), _('Feb'), _('Mar'), _('Apr'), _('May'), _('Jun'),
75
 
        _('Jul'), _('Aug'), _('Sep'), _('Oct'), _('Nov'), _('Dec')
76
 
        ]
77
 
 
78
 
    # pylint: disable-msg=W0612
79
 
    tzname = _('Server Local Time')
80
 
    if isinstance(date, str):
81
 
        try:
82
 
            year, mon, day, hh, mm, ss, wday, ydat, dst = time.strptime(date)
83
 
            if dst in (0, 1):
84
 
                tzname = time.tzname[dst]
85
 
            else:
86
 
                # MAS: No exception but dst = -1 so try
87
 
                return ctime(time.mktime((year, mon, day, hh, mm, ss, wday,
88
 
                                          ydat, dst)))
89
 
        except (ValueError, AttributeError):
90
 
            try:
91
 
                wday, mon, day, hms, year = date.split()
92
 
                hh, mm, ss = hms.split(':')
93
 
                year = int(year)
94
 
                day = int(day)
95
 
                hh = int(hh)
96
 
                mm = int(mm)
97
 
                ss = int(ss)
98
 
            except ValueError:
99
 
                return date
100
 
            else:
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():
104
 
                        wday = i
105
 
                        break
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():
109
 
                        mon = i
110
 
                        break
111
 
    else:
112
 
        # pylint: disable-msg=W0612
113
 
        year, mon, day, hh, mm, ss, wday, yday, dst = time.localtime(date)
114
 
        if dst in (0, 1):
115
 
            tzname = time.tzname[dst]
116
 
 
117
 
    wday = daysofweek[wday]
118
 
    mon = months[mon]
119
 
    return _('$wday $mon $day $hh:$mm:$ss $tzname $year')