[or-cvs] r17933: {projects} fix locale directory error (projects/gettor)

ioerror at seul.org ioerror at seul.org
Mon Jan 5 23:18:45 UTC 2009


Author: ioerror
Date: 2009-01-05 18:18:45 -0500 (Mon, 05 Jan 2009)
New Revision: 17933

Modified:
   projects/gettor/gettor.py
   projects/gettor/gettor_config.py
Log:
fix locale directory error


Modified: projects/gettor/gettor.py
===================================================================
--- projects/gettor/gettor.py	2009-01-05 23:12:49 UTC (rev 17932)
+++ projects/gettor/gettor.py	2009-01-05 23:18:45 UTC (rev 17933)
@@ -69,9 +69,9 @@
 
 
 # Switch language to 'newlocale'. Return default if language is not supported.
-def switchLocale(newlocale):
+def switchLocale(newlocale, localedir):
     trans = gettext.translation("gettor", 
-                                "/usr/share/locale", 
+                                localedir,
                                 [newlocale], 
                                 fallback=True)
     trans.install()
@@ -169,7 +169,13 @@
     gettor_log.initialize()
     log = gettor_log.getLogger()
     logLang = conf.getLocale()
-    switchLocale(logLang)
+    localeDir = conf.getLocaleDir()
+    # Just check for the english .mo file, because that's the fallback
+    englishMoFile = localeDir + "/en/LC_MESSAGES/gettor.mo"
+    if not os.path.isfile(englishMoFile):
+        log.error("Sorry, %s is not a file we can access." % englishMoFile)
+        return False
+    switchLocale(logLang, localeDir)
     distDir = conf.getDistDir()
     if not os.path.isdir(distDir):
         log.error(_("Sorry, %s is not a directory.") % distDir)
@@ -267,7 +273,7 @@
 
 if __name__ == "__main__":
     if not main():
-        print >> sys.stderr, _("Main loop exited with errors.")
+        print >> sys.stderr, "Main loop exited with errors."
         exit(1)
     else:
         exit(0)

Modified: projects/gettor/gettor_config.py
===================================================================
--- projects/gettor/gettor_config.py	2009-01-05 23:12:49 UTC (rev 17932)
+++ projects/gettor/gettor_config.py	2009-01-05 23:18:45 UTC (rev 17933)
@@ -24,6 +24,7 @@
      locale = en
      logSubSystem = nothing
      logFile = /dev/null
+     localeDir = /usr/share/locale
 
  Note that you can set from none to any of these values in your config file.
  Values you dont provide will be taken from the defaults in 'useConf'.
@@ -43,6 +44,8 @@
                 'file':     Logmessages will be written to a file (Not that 
                             this needs the 'logFile' option in the config file
                             also set to something useful
+ localeDir:     This is where the 'en/LC_MESSAGES/gettor.mo' or 
+                'whateverlang/LC_MESSAGES/gettor.mo' should go
 
  If no valid config file is provided to __init__, gettorConf will try to use
  '~/.gettorrc' as default config file. If that fails, the default values from
@@ -86,7 +89,8 @@
                         "packDir":      ("/var/lib/gettor/pkg/",    "global"),
                         "locale":       ("en",                      "global"),
                         "logSubSystem": ("nothing",                 "global"),
-                        "logFile":      ("/dev/null",               "global")}
+                        "logFile":      ("/dev/null",               "global"),
+                        "localeDir":    ("/usr/share/locale",       "global")}
 
         # One ConfigParser instance to read the actual values from config
         self.config = ConfigParser.ConfigParser()
@@ -159,6 +163,9 @@
     def getLogFile(self):
         return self.useConf["logFile"][0]
 
+    def getLocaleDir(self):
+        return self.useConf["localeDir"][0]
+
 if __name__ == "__main__" :
     c = gettorConf()
     print "# This is a suitable default configuration. Tune to fit your needs."



More information about the tor-commits mailing list