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

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Mar 8 15:53:24 PST 2014


Author: marisn
Date: 2014-03-08 15:53:24 -0800 (Sat, 08 Mar 2014)
New Revision: 59215

Modified:
   grass/trunk/lib/init/grass.py
Log:
Always set locale for GRASS during startup; gettext needs LANG environmental variable on Windows even for default locale

Modified: grass/trunk/lib/init/grass.py
===================================================================
--- grass/trunk/lib/init/grass.py	2014-03-08 22:20:17 UTC (rev 59214)
+++ grass/trunk/lib/init/grass.py	2014-03-08 23:53:24 UTC (rev 59215)
@@ -763,24 +763,34 @@
     # not accepting ISO codes as valid locale identifiers http://bugs.python.org/issue10466
     import locale
     
+    language = 'None' # Such string sometimes is present in wx file
+    
     # Override value is stored in wxGUI preferences file.
     # As it's the only thing required, we'll just grep it out.
     try:
         fd = open(os.path.join(grass_config_dir, 'wx'), 'r')
     except:
-        # Language override has not been defined or is inaccessible
-        return
-    language = 'None' # Such string sometimes is present in wx file
-    for line in fd:
-        if re.search('^language', line):
-            line = line.rstrip('%s' % os.linesep)
-            language = ''.join(line.split(';')[-1:])
-            break
-    if language == 'None':
+        # Even if there is no override, we still need to set locale.
+        pass
+    else:
+        for line in fd:
+            if re.search('^language', line):
+                line = line.rstrip('%s' % os.linesep)
+                language = ''.join(line.split(';')[-1:])
+                break
+        fd.close()
+    
+    if language == 'None' or language == '' or not language:
         # Language override is disabled (system language specified)
         # As by default program runs with C locale, but users expect to
         # have their default locale, we'll just set default locale
         locale.setlocale(locale.LC_ALL, '')
+        if windows and os.getenv('LANG') is None:
+            language, encoding = locale.getdefaultlocale()
+            os.environ['LANG'] = language
+            gettext.install('grasslibs', os.path.join(gisbase, 'locale'), codeset=encoding)
+        else:
+            gettext.install('grasslibs', os.path.join(gisbase, 'locale'), unicode=True)
         return
     
     warning("A language override has been requested. Trying to switch GRASS into '%s'..." % language)



More information about the grass-commit mailing list