[GRASS-SVN] r52597 - grass/trunk/lib/init

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Aug 8 04:52:40 PDT 2012


Author: marisn
Date: 2012-08-08 04:52:40 -0700 (Wed, 08 Aug 2012)
New Revision: 52597

Modified:
   grass/trunk/lib/init/grass.py
Log:
Better support of system unsupported locales

Modified: grass/trunk/lib/init/grass.py
===================================================================
--- grass/trunk/lib/init/grass.py	2012-08-08 11:01:02 UTC (rev 52596)
+++ grass/trunk/lib/init/grass.py	2012-08-08 11:52:40 UTC (rev 52597)
@@ -653,25 +653,40 @@
     language = kv.get('LANG')
     if language:
         language = language.split('.')[0] # Split off ignored .encoding part if present
+        orig_language = language
         try:
-            locale.setlocale(locale.LC_MESSAGES, language)
+            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_MESSAGES, 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_MESSAGES to %s as defined by g.gisenv LANG parameter" % language
+                print "Failed to set LC_ALL to %s" % language
                 default_locale = locale.getdefaultlocale()
                 if default_locale[0]:
                     language = default_locale[0]
                 else:
                     language = 'C'
-        os.environ['LANGUAGE'] = language
-        os.environ['LANG'] = language
-        os.environ['LC_MESSAGES'] = language
+        
+        # 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
+        
         # Calling gettext.install twice seems to allow to see also localized startup messages
         # Black magic ;)
         gettext.install('grasslibs', os.path.join(gisbase, 'locale'), unicode = True)



More information about the grass-commit mailing list