[or-cvs] r21029: {projects} Towards sending out localized packages: Almost there. Thanks (projects/gettor/lib/gettor)

kaner at seul.org kaner at seul.org
Fri Nov 27 12:36:29 UTC 2009


Author: kaner
Date: 2009-11-27 07:36:29 -0500 (Fri, 27 Nov 2009)
New Revision: 21029

Modified:
   projects/gettor/lib/gettor/packages.py
   projects/gettor/lib/gettor/requests.py
   projects/gettor/lib/gettor/responses.py
Log:
Towards sending out localized packages: Almost there. Thanks to Robert (kventil) for testing


Modified: projects/gettor/lib/gettor/packages.py
===================================================================
--- projects/gettor/lib/gettor/packages.py	2009-11-26 22:34:52 UTC (rev 21028)
+++ projects/gettor/lib/gettor/packages.py	2009-11-27 12:36:29 UTC (rev 21029)
@@ -25,16 +25,16 @@
 
 class Packages:
     #                "bundle name": ("single file regex", "split file regex")
-    packageRegex = { "tor-browser-bundle_en-US": ("tor-browser-.*_en-US.exe$", "tor-browser-.*_en-US_split"),
-                     "tor-im-browser-bundle_en-US": ("tor-im-browser-.*_en-US.exe$", "tor-im-browser-.*_en-US_split"),
+    packageRegex = { "tor-browser-bundle_en": ("tor-browser-.*_en-US.exe$", "tor-browser-.*_en-US_split"),
+                     "tor-im-browser-bundle_en": ("tor-im-browser-.*_en-US.exe$", "tor-im-browser-.*_en-US_split"),
                      "tor-browser-bundle_de": ("tor-browser-.*_de.exe$", "tor-browser-.*_de_split"),
                      "tor-im-browser-bundle_de": ("tor-im-browser-.*_de.exe$", "tor-im-browser-.*_de_split"),
                      "tor-browser-bundle_ar": ("tor-browser-.*_ar.exe$", "tor-browser-.*_ar_split"),
                      "tor-im-browser-bundle_ar": ("tor-im-browser-.*_ar.exe$", "tor-im-browser-.*_ar_split"),
-                     "tor-browser-bundle_es-ES": ("tor-browser-.*_es-ES.exe$", "tor-browser-.*_es-ES_split"),
-                     "tor-im-browser-bundle_es-ES": ("tor-im-browser-.*_es-ES.exe$", "tor-im-browser-.*_es-ES_split"),
-                     "tor-browser-bundle_fa-IR": ("tor-browser-.*_fa-IR.exe$", "tor-browser-.*_fa-IR_split"),
-                     "tor-im-browser-bundle_fa-IR": ("tor-im-browser-.*_fa-IR.exe$", "tor-im-browser-.*_fa-IR_split"),
+                     "tor-browser-bundle_es": ("tor-browser-.*_es-ES.exe$", "tor-browser-.*_es-ES_split"),
+                     "tor-im-browser-bundle_es": ("tor-im-browser-.*_es-ES.exe$", "tor-im-browser-.*_es-ES_split"),
+                     "tor-browser-bundle_fa": ("tor-browser-.*_fa-IR.exe$", "tor-browser-.*_fa-IR_split"),
+                     "tor-im-browser-bundle_fa": ("tor-im-browser-.*_fa-IR.exe$", "tor-im-browser-.*_fa-IR_split"),
                      "tor-browser-bundle_fr": ("tor-browser-.*_fr.exe$", "tor-browser-.*_fr_split"),
                      "tor-im-browser-bundle_fr": ("tor-im-browser-.*_fr.exe$", "tor-im-browser-.*_fr_split"),
                      "tor-browser-bundle_it": ("tor-browser-.*_it.exe$", "tor-browser-.*_it_split"),

Modified: projects/gettor/lib/gettor/requests.py
===================================================================
--- projects/gettor/lib/gettor/requests.py	2009-11-26 22:34:52 UTC (rev 21028)
+++ projects/gettor/lib/gettor/requests.py	2009-11-27 12:36:29 UTC (rev 21029)
@@ -25,11 +25,19 @@
 
 class requestMail:
 
-    defaultLang = "en-US"
-    # XXX
-    supportedLangs = { "en-US": "English", 
+    defaultLang = "en"
+    # XXX Change this or remove this
+    supportedLangs = { "en": "English", 
                        "fa": "Farsi",
-                       "de": "Deutsch" }
+                       "de": "Deutsch",
+                       "ar": "Arabic",
+                       "es": "Spanish",
+                       "fr": "French",
+                       "it": "Italian",
+                       "nl": "Dutch",
+                       "pl": "Polish",
+                       "ru": "Russian",
+                       "zh-CN": "Chinese"  }
 
     def __init__(self, config):
         """ Read message from stdin, parse all the stuff we want to know
@@ -48,14 +56,19 @@
         except:
             pass
 
-        self.replyLocale = "en-US"
+        self.replyLocale = self.defaultLang
         # We want to parse, log and act on the "To" field
         self.toAddress = self.parsedMessage["to"]
         log.info("User made request to %s" % self.toAddress)
         # Check if we got a '+' address
         match = re.search('(?<=\+)\w+', self.toAddress)
         if match:
-            self.replyLocale = match.group(0)
+            # Cut back and front
+            splitFrontPart = self.toAddress.split('@')
+            assert len(splitFrontPart) > 0, "Splitting To: address failed"
+            splitLang = splitFrontPart[0].rsplit('+')
+            assert len(splitLang) > 1, "Splitting for language failed"
+            self.replyLocale = splitLang[1]
             log.info("User requested language %s" % self.replyLocale)
         # TODO XXX: 
         # Scrub this data

Modified: projects/gettor/lib/gettor/responses.py
===================================================================
--- projects/gettor/lib/gettor/responses.py	2009-11-26 22:34:52 UTC (rev 21028)
+++ projects/gettor/lib/gettor/responses.py	2009-11-27 12:36:29 UTC (rev 21029)
@@ -29,7 +29,7 @@
 
 def sendNotification(config, sendTo):
     """Send notification to user"""
-    response = Response(config, sendTo, "en", "", False, True, "")
+    response = Response(config, sendTo, None, "", False, True, "")
     message = gettor.constants.mailfailmsg
     return response.sendGenericMessage(message)
 
@@ -40,9 +40,9 @@
         self.srcEmail = "GetTor <gettor at torproject.org>"
         self.replyTo = replyto
         assert self.replyTo is not None, "Empty replyto address."
-        # Default lang to en_US
+        # Default lang is en
         if lang is None:
-            lang = "en-US"
+            lang = "en"
         self.mailLang = lang
         # XXX If someone wants one of the localizable packages, add language 
         # suffix



More information about the tor-commits mailing list