[CalendarServer-changes] [7887] CalendarServer/branches/users/glyph/imip-and-admin-html/ twistedcaldav/mail.py

source_changes at macosforge.org source_changes at macosforge.org
Thu Aug 11 21:37:43 PDT 2011


Revision: 7887
          http://trac.macosforge.org/projects/calendarserver/changeset/7887
Author:   glyph at apple.com
Date:     2011-08-11 21:37:42 -0700 (Thu, 11 Aug 2011)
Log Message:
-----------
split out localized label generation to a function

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/mail.py

Modified: CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/mail.py
===================================================================
--- CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/mail.py	2011-08-12 04:37:30 UTC (rev 7886)
+++ CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/mail.py	2011-08-12 04:37:42 UTC (rev 7887)
@@ -144,7 +144,53 @@
     """
 
 
+def localizedLabels(language, canceled, inviteState):
+    """
+    Generate localized labels for an email in the given language.
 
+    @param language: a 2-letter language code
+
+    @type language: C{str}
+
+    @return: a 2-tuple of (subjectFormatString, labelDict), where the first is a
+        format string for use in the subject, and the latter is a dictionary
+        with labels suitable for filling out HTML and plain-text templates.  All
+        values are C{str}s.
+    """
+    with translationTo(language):
+        if canceled:
+            subjectFormatString = _("Event canceled: %(summary)s")
+        elif inviteState == "new":
+            subjectFormatString = _("Event invitation: %(summary)s")
+        elif inviteState == "update":
+            subjectFormatString = _("Event update: %(summary)s")
+        else:
+            subjectFormatString = _("Event reply: %(summary)s")
+
+        if canceled:
+            inviteLabel = _("Event Canceled")
+        else:
+            if inviteState == "new":
+                inviteLabel = _("Event Invitation")
+            elif inviteState == "update":
+                inviteLabel = _("Event Update")
+            else:
+                inviteLabel = _("Event Reply")
+
+        labels = dict(
+            dateLabel = _("Date"),
+            timeLabel = _("Time"),
+            durationLabel = _("Duration"),
+            recurrenceLabel = _("Occurs"),
+            descLabel = _("Description"),
+            orgLabel = _("Organizer"),
+            attLabel = _("Attendees"),
+            locLabel = _("Location"),
+            inviteLabel = inviteLabel,
+        )
+
+    return subjectFormatString, labels
+
 #
 # Mail gateway service config
 #
@@ -1201,47 +1247,22 @@
         msgId = messageid()
         msg["Message-ID"] = msgId
 
-        with translationTo(language):
-            if canceled:
-                formatString = _("Event canceled: %(summary)s")
-            elif inviteState == "new":
-                formatString = _("Event invitation: %(summary)s")
-            elif inviteState == "update":
-                formatString = _("Event update: %(summary)s")
-            else:
-                formatString = _("Event reply: %(summary)s")
+        subjectFormat, labels = localizedLabels(language, canceled, inviteState)
 
-            # The translations we get back from gettext are utf-8 encoded
-            # strings, so convert to unicode
-            formatString = formatString.decode("utf-8")
+        # The translations we get back from gettext are utf-8 encoded strings,
+        # so convert to unicode.
 
-            details['subject'] = msg['Subject'] = formatString % {
-                'summary' : details['summary']
-            }
+        details['subject'] = msg['Subject'] = subjectFormat.decode('utf-8') % {
+            'summary' : details['summary']
+        }
 
+        details.update(labels)
+
+        with translationTo(language):
+
             msgAlt = MIMEMultipart("alternative")
             msg.attach(msgAlt)
 
-            # Get localized labels
-            if canceled:
-                details['inviteLabel'] = _("Event Canceled")
-            else:
-                if inviteState == "new":
-                    details['inviteLabel'] = _("Event Invitation")
-                elif inviteState == "update":
-                    details['inviteLabel'] = _("Event Update")
-                else:
-                    details['inviteLabel'] = _("Event Reply")
-
-            details['dateLabel'] = _("Date")
-            details['timeLabel'] = _("Time")
-            details['durationLabel'] = _("Duration")
-            details['recurrenceLabel'] = _("Occurs")
-            details['descLabel'] = _("Description")
-            details['orgLabel'] = _("Organizer")
-            details['attLabel'] = _("Attendees")
-            details['locLabel'] = _("Location")
-
             plainAttendeeList = []
             for cn, mailto in attendees:
                 if cn:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110811/a96aeb81/attachment.html>


More information about the calendarserver-changes mailing list