[GRASS-SVN] r53501 - grass/branches/releasebranch_6_4/gui/wxpython/core

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Oct 19 07:37:05 PDT 2012


Author: martinl
Date: 2012-10-19 07:37:05 -0700 (Fri, 19 Oct 2012)
New Revision: 53501

Modified:
   grass/branches/releasebranch_6_4/gui/wxpython/core/globalvar.py
   grass/branches/releasebranch_6_4/gui/wxpython/core/settings.py
Log:
wxGUI: fix language support for wxGUI


Modified: grass/branches/releasebranch_6_4/gui/wxpython/core/globalvar.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/core/globalvar.py	2012-10-19 14:25:52 UTC (rev 53500)
+++ grass/branches/releasebranch_6_4/gui/wxpython/core/globalvar.py	2012-10-19 14:37:05 UTC (rev 53501)
@@ -184,6 +184,46 @@
                     
     Debug.msg(1, "Number of new AddOn commands: %d", nCmd)
 
+def SetLanguage():
+    import locale
+    
+    language = os.getenv('LANG')
+    if language:
+        language = language.split('.')[0] # Split off ignored .encoding part if present
+        orig_language = language
+        try:
+            locale.setlocale(locale.LC_ALL, language)
+        except:
+            try:
+                # Locale lang.encoding might be missing. Let's try UTF-8 encoding before giving up
+                # as on Linux systems lang.UTF-8 locales are more common than legacy ISO-8859 ones.
+                language = locale.normalize('%s.UTF-8' % language)
+                locale.setlocale(locale.LC_ALL, language)
+            except:
+                # If we got so far, provided locale is not supported on this system
+                print "Failed to set LC_ALL to %s" % language
+                default_locale = locale.getdefaultlocale()
+                if default_locale[0]:
+                    language = default_locale[0]
+                else:
+                    language = 'C'
+        
+        # Set up environment for subprocesses
+        for lc in ('LC_CTYPE', 'LC_MESSAGES', 'LC_TIME', 'LC_COLLATE', 'LC_MONETARY', 'LC_PAPER', 'LC_NAME', 'LC_ADDRESS', 'LC_TELEPHONE', 'LC_MEASUREMENT', 'LC_IDENTIFICATION'):
+            os.environ[lc] = language
+        
+        # Some code in GRASS might not like other decimal separators than .
+        # Other potential sources for problems are: LC_TIME LC_CTYPE
+        locale.setlocale(locale.LC_NUMERIC, 'C')
+        os.environ['LC_NUMERIC'] = 'C'
+        if os.getenv('LC_ALL'):
+            del os.environ['LC_ALL'] # Remove LC_ALL to not override LC_NUMERIC
+        
+        # Even if setting locale has failed, let's set LANG in a hope, that UI will use it
+        # GRASS texts will be in selected language, system messages (i.e. OK, Cancel etc.) - in system default language
+        os.environ['LANGUAGE'] = orig_language
+        os.environ['LANG'] = orig_language
+
 """@brief Collected GRASS-relared binaries/scripts"""
 grassCmd, grassScripts = GetGRASSCommands()
 Debug.msg(1, "Number of GRASS commands: %d", len(grassCmd))
@@ -200,3 +240,5 @@
 
 """@Check version of wxPython, use agwStyle for 2.8.11+"""
 hasAgw = CheckWxVersion()
+
+SetLanguage()

Modified: grass/branches/releasebranch_6_4/gui/wxpython/core/settings.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/core/settings.py	2012-10-19 14:25:52 UTC (rev 53500)
+++ grass/branches/releasebranch_6_4/gui/wxpython/core/settings.py	2012-10-19 14:37:05 UTC (rev 53501)
@@ -76,8 +76,6 @@
         except KeyError:
             projFile = ''
         
-        id_loc = self._generateLocale()
-        
         self.defaultSettings = {
             #
             # general
@@ -152,7 +150,7 @@
             #
             'language': {
                 'locale': {
-                    'lc_all' : id_loc
+                    'lc_all' : self._generateLocale(),
                 }
             },
             #



More information about the grass-commit mailing list