Ver código fonte

wxGUI: don't fail when locale is invalid

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@51371 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 13 anos atrás
pai
commit
bedeec04dc
2 arquivos alterados com 17 adições e 5 exclusões
  1. 6 1
      gui/wxpython/core/gcmd.py
  2. 11 4
      gui/wxpython/core/settings.py

+ 6 - 1
gui/wxpython/core/gcmd.py

@@ -67,8 +67,13 @@ def DecodeString(string):
     """
     if not string:
         return string
+
+    try:
+        enc = locale.getdefaultlocale()[1]
+    except ValueError, e:
+        sys.stderr.write(_("ERROR: %s\n") % str(e))
+        return string
     
-    enc = locale.getdefaultlocale()[1]
     if enc:
         Debug.msg(5, "DecodeString(): enc=%s" % enc)
         return string.decode(enc)

+ 11 - 4
gui/wxpython/core/settings.py

@@ -54,13 +54,20 @@ class Settings:
     def _generateLocale(self):
         """!Generate locales
         """
-        loc = list(locale.getdefaultlocale())
-        if loc[1] == 'UTF8':
-            loc[1] = 'UTF-8'
-        code_loc = "%s.%s" % (loc[0],loc[1])
+        # collect available locales
         self.locs = list(set(locale.locale_alias.values()))
         self.locs.append('en_GB.UTF-8')
         self.locs.sort()
+        
+        try:
+            loc = list(locale.getdefaultlocale())
+        except ValueError, e:
+            sys.stderr.write(_('ERROR: %s\n') % str(e))
+            return 'C'
+        
+        if loc[1] == 'UTF8':
+            loc[1] = 'UTF-8'
+        code_loc = "%s.%s" % (loc[0], loc[1])
         if code_loc in self.locs:
             return code_loc