Skip to content

Commit f9457e5

Browse files
author
Alexander Smishlajev
committed
translate UI messages (patch [SF#1462491])
1 parent 87ff727 commit f9457e5

File tree

1 file changed

+69
-59
lines changed

1 file changed

+69
-59
lines changed

roundup/mailgw.py

Lines changed: 69 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class node. Any parts of other types are each stored in separate files
7272
an exception, the original message is bounced back to the sender with the
7373
explanatory message given in the exception.
7474
75-
$Id: mailgw.py,v 1.174 2006-03-03 00:13:20 richard Exp $
75+
$Id: mailgw.py,v 1.175 2006-04-06 06:01:35 a1s Exp $
7676
"""
7777
__docformat__ = 'restructuredtext'
7878

@@ -82,6 +82,7 @@ class node. Any parts of other types are each stored in separate files
8282

8383
from roundup import hyperdb, date, password, rfc2822, exceptions
8484
from roundup.mailer import Mailer, MessageSendError
85+
from roundup.i18n import _
8586

8687
SENDMAILDEBUG = os.environ.get('SENDMAILDEBUG', '')
8788

@@ -582,9 +583,9 @@ def handle_message(self, message):
582583
# handle the subject line
583584
subject = message.getheader('subject', '')
584585
if not subject:
585-
raise MailUsageError, '''
586+
raise MailUsageError, _("""
586587
Emails to Roundup trackers must include a Subject: line!
587-
'''
588+
""")
588589

589590
# detect Precedence: Bulk, or Microsoft Outlook autoreplies
590591
if (message.getheader('precedence', '') == 'bulk'
@@ -670,7 +671,7 @@ def handle_message(self, message):
670671
m = None
671672

672673
if not m and pfxmode == 'strict':
673-
raise MailUsageError, """
674+
raise MailUsageError, _("""
674675
The message you sent to roundup did not contain a properly formed subject
675676
line. The subject must contain a class name or designator to indicate the
676677
'topic' of the message. For example:
@@ -681,8 +682,8 @@ def handle_message(self, message):
681682
- this will append the message's contents to the existing issue 1234
682683
in the tracker.
683684
684-
Subject was: '%s'
685-
"""%subject
685+
Subject was: '%(subject)s'
686+
""") % locals()
686687

687688
# try to get the class specified - if "loose" then fall back on the
688689
# default
@@ -700,13 +701,14 @@ def handle_message(self, message):
700701
except KeyError:
701702
pass
702703
if not cl:
703-
raise MailUsageError, '''
704-
The class name you identified in the subject line ("%s") does not exist in the
704+
validname = ', '.join(self.db.getclasses())
705+
raise MailUsageError, _("""
706+
The class name you identified in the subject line ("%(classname)s") does not exist in the
705707
database.
706708
707-
Valid class names are: %s
708-
Subject was: "%s"
709-
'''%(classname, ', '.join(self.db.getclasses()), subject)
709+
Valid class names are: %(validname)s
710+
Subject was: "%(subject)s"
711+
""") % locals()
710712

711713
# get the optional nodeid
712714
if pfxmode == 'none':
@@ -728,13 +730,13 @@ def handle_message(self, message):
728730

729731
# but we do need either a title or a nodeid...
730732
if nodeid is None and not title:
731-
raise MailUsageError, '''
733+
raise MailUsageError, _("""
732734
I cannot match your message to a node in the database - you need to either
733735
supply a full designator (with number, eg "[issue123]" or keep the
734736
previous subject title intact so I can match that.
735737
736-
Subject was: "%s"
737-
'''%subject
738+
Subject was: "%(subject)s"
739+
""") % locals()
738740

739741
# If there's no nodeid, check to see if this is a followup and
740742
# maybe someone's responded to the initial mail that created an
@@ -761,12 +763,12 @@ def handle_message(self, message):
761763
# if a nodeid was specified, make sure it's valid
762764
if nodeid is not None and not cl.hasnode(nodeid):
763765
if pfxmode == 'strict':
764-
raise MailUsageError, '''
765-
The node specified by the designator in the subject of your message ("%s")
766-
does not exist.
766+
raise MailUsageError, _("""
767+
The node specified by the designator in the subject of your message
768+
("%(nodeid)s") does not exist.
767769
768-
Subject was: "%s"
769-
'''%(nodeid, subject)
770+
Subject was: "%(subject)s"
771+
""") % locals()
770772
else:
771773
title = subject
772774
nodeid = None
@@ -788,11 +790,12 @@ def handle_message(self, message):
788790
# we should chect for subclasses of these classes,
789791
# not for the class name...
790792
if current_class not in ('msg', 'file', 'user', 'issue'):
791-
raise MailUsageError, '''
793+
mailadmin = config['ADMIN_EMAIL']
794+
raise MailUsageError, _("""
792795
The mail gateway is not properly set up. Please contact
793-
%s and have them fix the incorrect class specified as:
794-
%s
795-
''' % (config['ADMIN_EMAIL'], current_class)
796+
%(mailadmin)s and have them fix the incorrect class specified as:
797+
%(current_class)s
798+
""") % locals()
796799
if option in ('-S', '--set'):
797800
if current_class == 'issue' :
798801
errors, issue_props = setPropArrayFromString(self,
@@ -810,11 +813,12 @@ def handle_message(self, message):
810813
errors, user_props = setPropArrayFromString(self,
811814
temp_cl, propstring.strip())
812815
if errors:
813-
raise MailUsageError, '''
816+
mailadmin = config['ADMIN_EMAIL']
817+
raise MailUsageError, _("""
814818
The mail gateway is not properly set up. Please contact
815-
%s and have them fix the incorrect properties:
816-
%s
817-
'''%(config['ADMIN_EMAIL'], errors)
819+
%(mailadmin)s and have them fix the incorrect properties:
820+
%(errors)s
821+
""") % locals()
818822

819823
#
820824
# handle the users
@@ -839,27 +843,29 @@ def handle_message(self, message):
839843
if not self.db.security.hasPermission('Email Access', author):
840844
if author == anonid:
841845
# we're anonymous and we need to be a registered user
842-
raise Unauthorized, '''
846+
from_address = from_list[0][1]
847+
raise Unauthorized, _("""
843848
You are not a registered user.
844849
845-
Unknown address: %s
846-
'''%from_list[0][1]
850+
Unknown address: %(from_address)s
851+
""") % locals()
847852
else:
848853
# we're registered and we're _still_ not allowed access
849-
raise Unauthorized, 'You are not permitted to access '\
850-
'this tracker.'
854+
raise Unauthorized, _(
855+
'You are not permitted to access this tracker.')
851856

852857
# make sure they're allowed to edit or create this class of information
853858
if nodeid:
854859
if not self.db.security.hasPermission('Edit', author, classname,
855860
itemid=nodeid):
856-
raise Unauthorized, 'You are not permitted to '\
857-
'edit %s.'%classname
861+
raise Unauthorized, _(
862+
'You are not permitted to edit %(classname)s.') % locals()
858863
else:
859864
if not self.db.security.hasPermission('Create', author, classname):
860-
raise Unauthorized, 'You are not permitted to '\
861-
'create %s.'%classname
862-
865+
raise Unauthorized, _(
866+
'You are not permitted to create %(classname)s.'
867+
) % locals()
868+
863869
# the author may have been created - make sure the change is
864870
# committed before we reopen the database
865871
self.db.commit()
@@ -904,12 +910,12 @@ def handle_message(self, message):
904910
if errors:
905911
if sfxmode == 'strict':
906912
errors = '\n- '.join(map(str, errors))
907-
raise MailUsageError, '''
913+
raise MailUsageError, _("""
908914
There were problems handling your subject line argument list:
909-
- %s
915+
- %(errors)s
910916
911-
Subject was: "%s"
912-
'''%(errors, subject)
917+
Subject was: "%(subject)s"
918+
""") % locals()
913919
else:
914920
title += ' ' + argswhole
915921

@@ -933,10 +939,10 @@ def handle_message(self, message):
933939
# now handle the body - find the message
934940
content, attachments = message.extract_content()
935941
if content is None:
936-
raise MailUsageError, '''
942+
raise MailUsageError, _("""
937943
Roundup requires the submission to be plain text. The message parser could
938944
not find a text/plain part to use.
939-
'''
945+
""")
940946

941947
# figure how much we should muck around with the email body
942948
keep_citations = config['MAILGW_KEEP_QUOTED_TEXT']
@@ -954,7 +960,8 @@ def handle_message(self, message):
954960
files = []
955961
for (name, mime_type, data) in attachments:
956962
if not self.db.security.hasPermission('Create', author, 'file'):
957-
raise Unauthorized, 'You are not permitted to create files.'
963+
raise Unauthorized, _(
964+
'You are not permitted to create files.')
958965
if not name:
959966
name = "unnamed"
960967
try:
@@ -967,8 +974,9 @@ def handle_message(self, message):
967974
# attach the files to the issue
968975
if not self.db.security.hasPermission('Edit', author,
969976
classname, 'files'):
970-
raise Unauthorized, 'You are not permitted to add '\
971-
'files to %s.'%classname
977+
raise Unauthorized, _(
978+
'You are not permitted to add files to %(classname)s.'
979+
) % locals()
972980

973981
if nodeid:
974982
# extend the existing files list
@@ -984,23 +992,25 @@ def handle_message(self, message):
984992
#
985993
if (content and properties.has_key('messages')):
986994
if not self.db.security.hasPermission('Create', author, 'msg'):
987-
raise Unauthorized, 'You are not permitted to create messages.'
995+
raise Unauthorized, _(
996+
'You are not permitted to create messages.')
988997

989998
try:
990999
message_id = self.db.msg.create(author=author,
9911000
recipients=recipients, date=date.Date('.'),
9921001
summary=summary, content=content, files=files,
9931002
messageid=messageid, inreplyto=inreplyto, **msg_props)
9941003
except exceptions.Reject, error:
995-
raise MailUsageError, '''
1004+
raise MailUsageError, _("""
9961005
Mail message was rejected by a detector.
997-
%s
998-
'''%error
1006+
%(error)s
1007+
""") % locals()
9991008
# attach the message to the node
10001009
if not self.db.security.hasPermission('Edit', author,
10011010
classname, 'messages'):
1002-
raise Unauthorized, 'You are not permitted to add '\
1003-
'messages to %s.'%classname
1011+
raise Unauthorized, _(
1012+
'You are not permitted to add messages to %(classname)s.'
1013+
) % locals()
10041014

10051015
if nodeid:
10061016
# add the message to the node's list
@@ -1026,18 +1036,18 @@ def handle_message(self, message):
10261036
for prop in props.keys():
10271037
if not self.db.security.hasPermission('Edit', author,
10281038
classname, prop):
1029-
raise Unauthorized, 'You are not permitted to edit '\
1030-
'property %s of class %s.'%(prop,classname)
1039+
raise Unauthorized, _('You are not permitted to edit '
1040+
'property %(prop)s of class %(classname)s.') % locals()
10311041

10321042
if nodeid:
10331043
cl.set(nodeid, **props)
10341044
else:
10351045
nodeid = cl.create(**props)
10361046
except (TypeError, IndexError, ValueError), message:
1037-
raise MailUsageError, '''
1047+
raise MailUsageError, _("""
10381048
There was a problem with the message you sent:
1039-
%s
1040-
'''%message
1049+
%(message)s
1050+
""") % locals()
10411051

10421052
# commit the changes to the DB
10431053
self.db.commit()
@@ -1056,8 +1066,8 @@ def setPropArrayFromString(self, cl, propString, nodeid=None):
10561066
try:
10571067
propname, value = prop.split('=')
10581068
except ValueError, message:
1059-
errors.append('not of form [arg=value,value,...;'
1060-
'arg=value,value,...]')
1069+
errors.append(_('not of form [arg=value,value,...;'
1070+
'arg=value,value,...]'))
10611071
return (errors, props)
10621072
# convert the value to a hyperdb-usable value
10631073
propname = propname.strip()

0 commit comments

Comments
 (0)