Skip to content

Commit 8ae6ad9

Browse files
author
Richard Jones
committed
i18n'ification
1 parent 5d3b0cd commit 8ae6ad9

File tree

4 files changed

+57
-39
lines changed

4 files changed

+57
-39
lines changed

cgi-bin/roundup.cgi

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: roundup.cgi,v 1.22 2001-12-13 00:20:01 richard Exp $
19+
# $Id: roundup.cgi,v 1.23 2002-01-05 02:19:03 richard Exp $
2020

2121
# python version check
2222
from roundup import version_check
23+
from roundup.i18n import _
2324

2425
#
2526
## Configuration
@@ -68,7 +69,7 @@ try:
6869
from roundup import cgitb
6970
except:
7071
print "Content-Type: text/html\n"
71-
print "Failed to import cgitb.<pre>"
72+
print _("Failed to import cgitb.<pre>")
7273
s = StringIO.StringIO()
7374
traceback.print_exc(None, s)
7475
print cgi.escape(s.getvalue()), "</pre>"
@@ -161,15 +162,15 @@ def main(out, err):
161162
request.send_header('Content-Type', 'text/html')
162163
request.end_headers()
163164
w = request.write
164-
w('<html><head><title>Roundup instances index</title></head>\n')
165-
w('<body><h1>Roundup instances index</h1><ol>\n')
165+
w(_('<html><head><title>Roundup instances index</title></head>\n'))
166+
w(_('<body><h1>Roundup instances index</h1><ol>\n'))
166167
homes = ROUNDUP_INSTANCE_HOMES.keys()
167168
homes.sort()
168169
for instance in homes:
169-
w('<li><a href="%s/%s/index">%s</a>\n'%(
170-
os.environ['SCRIPT_NAME'], urllib.quote(instance),
171-
cgi.escape(instance)))
172-
w('</ol></body></html>')
170+
w(_('<li><a href="%(instance_url)s/index">%(instance_name)s</a>\n')%{
171+
'instance_url': os.environ['SCRIPT_NAME']+'/'+urllib.quote(instance),
172+
'instance_name': cgi.escape(instance)})
173+
w(_('</ol></body></html>'))
173174

174175
#
175176
# Now do the actual CGI handling
@@ -196,6 +197,10 @@ LOG.close()
196197

197198
#
198199
# $Log: not supported by cvs2svn $
200+
# Revision 1.22 2001/12/13 00:20:01 richard
201+
# . Centralised the python version check code, bumped version to 2.1.1 (really
202+
# needs to be 2.1.2, but that isn't released yet :)
203+
#
199204
# Revision 1.21 2001/12/02 05:06:16 richard
200205
# . We now use weakrefs in the Classes to keep the database reference, so
201206
# the close() method on the database is no longer needed.

roundup-mailgw

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: roundup-mailgw,v 1.18 2001-12-13 00:20:01 richard Exp $
19+
# $Id: roundup-mailgw,v 1.19 2002-01-05 02:19:03 richard Exp $
2020

2121
# python version check
2222
from roundup import version_check
2323

2424
import sys, os, re, cStringIO
2525

2626
from roundup.mailgw import Message
27+
from roundup.i18n import _
2728

2829
def do_pipe(handler):
2930
'''Read a message from standard input and pass it to the mail handler.
@@ -64,7 +65,7 @@ def do_pop(handler, server, user='', password=''):
6465
'''
6566
import getpass, poplib
6667
if not user:
67-
user = raw_input('User: ')
68+
user = raw_input(_('User: '))
6869
if not password:
6970
password = getpass.getpass()
7071

@@ -92,8 +93,8 @@ def do_pop(handler, server, user='', password=''):
9293
def usage(args, message=None):
9394
if message is not None:
9495
print message
95-
print 'Usage: %s <instance home> [source spec]'%args[0]
96-
print '''
96+
print _('Usage: %(program)s <instance home> [source spec]')%{'program': args[0]}
97+
print _('''
9798
The roundup mail gateway may be called in one of two ways:
9899
. with an instance home as the only argument,
99100
. with both an instance home and a mail spool file, or
@@ -120,7 +121,7 @@ POP:
120121
pop server
121122
are both valid. The username and/or password will be prompted for if
122123
not supplied on the command-line.
123-
'''
124+
''')
124125
return 1
125126

126127
def main(args):
@@ -148,7 +149,7 @@ def main(args):
148149

149150
# otherwise, figure what sort of mail source to handle
150151
if len(args) < 4:
151-
return usage(args, 'Error: not enough source specification information')
152+
return usage(args, _('Error: not enough source specification information'))
152153
source, specification = args[2:]
153154
if source == 'mailbox':
154155
return do_mailbox(handler, specification)
@@ -158,16 +159,20 @@ def main(args):
158159
if m:
159160
return do_pop(handler, m.group('server'), m.group('user'),
160161
m.group('pass'))
161-
return usage(args, 'Error: pop specification not valid')
162+
return usage(args, _('Error: pop specification not valid'))
162163

163-
return usage(args, 'Error: The source must be either "mailbox" or "pop"')
164+
return usage(args, _('Error: The source must be either "mailbox" or "pop"'))
164165

165166
# call main
166167
if __name__ == '__main__':
167168
sys.exit(main(sys.argv))
168169

169170
#
170171
# $Log: not supported by cvs2svn $
172+
# Revision 1.18 2001/12/13 00:20:01 richard
173+
# . Centralised the python version check code, bumped version to 2.1.1 (really
174+
# needs to be 2.1.2, but that isn't released yet :)
175+
#
171176
# Revision 1.17 2001/12/02 05:06:16 richard
172177
# . We now use weakrefs in the Classes to keep the database reference, so
173178
# the close() method on the database is no longer needed.

roundup-server

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@
1818
#
1919
""" HTTP Server that serves roundup.
2020
21-
Based on CGIHTTPServer in the Python library.
22-
23-
$Id: roundup-server,v 1.23 2001-12-15 23:47:07 richard Exp $
24-
21+
$Id: roundup-server,v 1.24 2002-01-05 02:19:03 richard Exp $
2522
"""
2623

2724
# python version check
@@ -33,6 +30,7 @@ import BaseHTTPServer
3330
# Roundup modules of use here
3431
from roundup import cgitb, cgi_client
3532
import roundup.instance
33+
from roundup.i18n import _
3634

3735
#
3836
## Configuration
@@ -103,12 +101,13 @@ class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
103101
self.send_header('Content-Type', 'text/html')
104102
self.end_headers()
105103
w = self.wfile.write
106-
w('<html><head><title>Roundup instances index</title></head>\n')
107-
w('<body><h1>Roundup instances index</h1><ol>\n')
104+
w(_('<html><head><title>Roundup instances index</title></head>\n'))
105+
w(_('<body><h1>Roundup instances index</h1><ol>\n'))
108106
for instance in self.ROUNDUP_INSTANCE_HOMES.keys():
109-
w('<li><a href="%s/index">%s</a>\n'%(urllib.quote(instance),
110-
cgi.escape(instance)))
111-
w('</ol></body></html>')
107+
w(_('<li><a href="%(instance_url)s/index">%(instance_name)s</a>\n')%{
108+
'instance_url': urllib.quote(instance),
109+
'instance_name': cgi.escape(instance)})
110+
w(_('</ol></body></html>'))
112111

113112
def inner_run_cgi(self):
114113
''' This is the inner part of the CGI handling
@@ -167,8 +166,9 @@ class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
167166
client.main()
168167

169168
def usage(message=''):
170-
if message: message = 'Error: %s\n\n'%message
171-
print '''%sUsage:
169+
if message:
170+
message = _('Error: %(error)s\n\n')%{'error': message}
171+
print _('''%(message)sUsage:
172172
roundup-server [-n hostname] [-p port] [name=instance home]*
173173
174174
-n: sets the host name
@@ -181,7 +181,7 @@ roundup-server [-n hostname] [-p port] [name=instance home]*
181181
"roundup-admin init". You may specify any number of these name=home
182182
pairs on the command-line. For convenience, you may edit the
183183
ROUNDUP_INSTANCE_HOMES variable in the roundup-server file instead.
184-
'''%message
184+
'''%locals()
185185
sys.exit(0)
186186

187187
def main():
@@ -207,18 +207,18 @@ def main():
207207
try:
208208
import pwd
209209
except ImportError:
210-
raise ValueError, "Can't change users - no pwd module"
210+
raise ValueError, _("Can't change users - no pwd module")
211211
try:
212212
uid = pwd.getpwnam(user)[2]
213213
except KeyError:
214-
raise ValueError, "User %s doesn't exist"%user
214+
raise ValueError, _("User %(user)s doesn't exist")%locals()
215215
os.setuid(uid)
216216
elif os.getuid() and user is not None:
217-
print 'WARNING: ignoring "-u" argument, not root'
217+
print _('WARNING: ignoring "-u" argument, not root')
218218

219219
# People can remove this check if they're really determined
220220
if not os.getuid() and user is None:
221-
raise ValueError, "Can't run as root!"
221+
raise ValueError, _("Can't run as root!")
222222

223223
# handle instance specs
224224
if args:
@@ -227,7 +227,7 @@ def main():
227227
try:
228228
name, home = arg.split('=')
229229
except ValueError:
230-
raise ValueError, "Instances must be name=home"
230+
raise ValueError, _("Instances must be name=home")
231231
d[name] = home
232232
RoundupRequestHandler.ROUNDUP_INSTANCE_HOMES = d
233233
except SystemExit:
@@ -240,14 +240,17 @@ def main():
240240
sys.argv = sys.argv[:1]
241241
address = (hostname, port)
242242
httpd = BaseHTTPServer.HTTPServer(address, RoundupRequestHandler)
243-
print 'Roundup server started on', address
243+
print _('Roundup server started on %(address)s')%locals()
244244
httpd.serve_forever()
245245

246246
if __name__ == '__main__':
247247
main()
248248

249249
#
250250
# $Log: not supported by cvs2svn $
251+
# Revision 1.23 2001/12/15 23:47:07 richard
252+
# sys module went away...
253+
#
251254
# Revision 1.22 2001/12/13 00:20:01 richard
252255
# . Centralised the python version check code, bumped version to 2.1.1 (really
253256
# needs to be 2.1.2, but that isn't released yet :)

roundup/cgitb.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#
22
# This module was written by Ka-Ping Yee, <[email protected]>.
33
#
4-
# $Id: cgitb.py,v 1.7 2001-11-22 15:46:42 jhermann Exp $
4+
# $Id: cgitb.py,v 1.8 2002-01-05 02:22:32 richard Exp $
55

66
__doc__ = """
77
Extended CGI traceback handler by Ka-Ping Yee, <[email protected]>.
88
"""
99

1010
import sys, os, types, string, keyword, linecache, tokenize, inspect, pydoc
1111

12+
from roundup.i18n import _
13+
1214
def breaker():
1315
return ('<body bgcolor="#f0f0ff">' +
1416
'<font color="#f0f0ff" size="-5"> > </font> ' +
@@ -23,10 +25,10 @@ def html(context=5):
2325
'<font size=+1><strong>%s</strong>: %s</font>'%(str(etype), str(evalue)),
2426
'#ffffff', '#aa55cc', pyver)
2527

26-
head = head + ('<p>A problem occurred while running a Python script. '
28+
head = head + (_('<p>A problem occurred while running a Python script. '
2729
'Here is the sequence of function calls leading up to '
2830
'the error, with the most recent (innermost) call first. '
29-
'The exception attributes are:')
31+
'The exception attributes are:'))
3032

3133
indent = '<tt><small>%s</small>&nbsp;</tt>' % ('&nbsp;' * 5)
3234
traceback = []
@@ -73,13 +75,13 @@ def linereader(file=file, lnum=[lnum]):
7375
if locals.has_key(name):
7476
value = pydoc.html.repr(locals[name])
7577
else:
76-
value = '<em>undefined</em>'
78+
value = _('<em>undefined</em>')
7779
name = '<strong>%s</strong>' % name
7880
else:
7981
if frame.f_globals.has_key(name):
8082
value = pydoc.html.repr(frame.f_globals[name])
8183
else:
82-
value = '<em>undefined</em>'
84+
value = _('<em>undefined</em>')
8385
name = '<em>global</em> <strong>%s</strong>' % name
8486
lvals.append('%s&nbsp;= %s' % (name, value))
8587
if lvals:
@@ -122,6 +124,9 @@ def handler():
122124

123125
#
124126
# $Log: not supported by cvs2svn $
127+
# Revision 1.7 2001/11/22 15:46:42 jhermann
128+
# Added module docstrings to all modules.
129+
#
125130
# Revision 1.6 2001/09/29 13:27:00 richard
126131
# CGI interfaces now spit up a top-level index of all the instances they can
127132
# serve.

0 commit comments

Comments
 (0)