[GRASS-SVN] r49670 - in grass/trunk: gui/wxpython/core gui/wxpython/gui_core lib/init

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Dec 12 04:12:29 EST 2011


Author: lucadelu
Date: 2011-12-12 01:12:29 -0800 (Mon, 12 Dec 2011)
New Revision: 49670

Modified:
   grass/trunk/gui/wxpython/core/settings.py
   grass/trunk/gui/wxpython/gui_core/preferences.py
   grass/trunk/lib/init/grass.py
Log:
add possibility to choose language in the preference dialog

Modified: grass/trunk/gui/wxpython/core/settings.py
===================================================================
--- grass/trunk/gui/wxpython/core/settings.py	2011-12-12 08:26:05 UTC (rev 49669)
+++ grass/trunk/gui/wxpython/core/settings.py	2011-12-12 09:12:29 UTC (rev 49670)
@@ -16,12 +16,14 @@
 (>=v2). Read the file COPYING that comes with GRASS for details.
 
 @author Martin Landa <landa.martin gmail.com>
+ at author Luca Delucchi <lucadeluge gmail.com> (language choice)
 """
 
 import os
 import sys
 import copy
 import types
+import locale
 
 from core       import globalvar
 from core.gcmd  import GException, GError
@@ -41,6 +43,17 @@
         except KeyError:
             projFile = ''
         
+        loc = list(locale.getdefaultlocale())
+        if loc[1] == 'UTF8':
+            loc[1] = 'UTF-8'
+        code_loc = "%s.%s" % (loc[0],loc[1])
+        self.locs = list(set(locale.locale_alias.values()))
+        self.locs.append('en_GB.UTF-8')
+        self.locs.sort()
+        try:
+            id_loc = locs.index(code_loc)
+        except:
+            id_loc = None
         #
         # default settings
         #
@@ -114,6 +127,14 @@
                     },
                 },
             #
+            # language
+            #
+            'language': {
+                'locale': {
+                    'lc_all' : id_loc
+                }
+            },
+            #
             # display
             #
             'display': {
@@ -724,6 +745,8 @@
              _("Collapse all except current"),
              _("Collapse all"),
              _("Expand all"))
+             
+        self.internalSettings['language']['locale']['choices'] = tuple(self.locs)
         self.internalSettings['atm']['leftDbClick']['choices'] = (_('Edit selected record'),
                                                                   _('Display selected'))
         

Modified: grass/trunk/gui/wxpython/gui_core/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/preferences.py	2011-12-12 08:26:05 UTC (rev 49669)
+++ grass/trunk/gui/wxpython/gui_core/preferences.py	2011-12-12 09:12:29 UTC (rev 49670)
@@ -23,11 +23,13 @@
 @author Michael Barton (Arizona State University)
 @author Martin Landa <landa.martin gmail.com>
 @author Vaclav Petras <wenzeslaus gmail.com> (menu customization)
+ at author Luca Delucchi <lucadeluge gmail.com> (language choice)
 """
 
 import os
 import sys
 import copy
+import locale
 try:
     import pwd
     havePwd = True
@@ -44,7 +46,7 @@
 
 from core          import globalvar
 from core.gcmd     import RunCommand
-from core.utils    import ListOfMapsets, GetColorTables, ReadEpsgCodes
+from core.utils    import ListOfMapsets, GetColorTables, ReadEpsgCodes, GetSettingsPath
 from core.settings import UserSettings
 
 wxSettingsChanged, EVT_SETTINGS_CHANGED = NewEvent()
@@ -160,6 +162,23 @@
         if self._updateSettings():
             self.settings.SaveToFile()
             self.parent.goutput.WriteLog(_('Settings saved to file \'%s\'.') % self.settings.filePath)
+            fileSettings = {}
+            self.settings.ReadSettingsFile(settings = fileSettings)
+            id_loc = fileSettings['language']['locale']['lc_all']
+            rcfile = open(os.path.join(GetSettingsPath(), 'bashrc'),"r")
+            rclines = rcfile.readlines()
+            rcfile.close()
+            rcfile = open(os.path.join(GetSettingsPath(), 'bashrc'),"w")
+            grasslang = False
+            for line in rclines:
+                if 'GRASS_LANG' in line:
+                    rcfile.write('GRASS_LANG: %s\n' % self.locales[id_loc])
+                    grasslang = True
+                else:
+                    rcfile.write('%s' % line)
+            if not grasslang:
+                rcfile.write('GRASS_LANG: %s\n' % self.locales[id_loc])
+            rcfile.close()
             event = wxSettingsChanged()
             wx.PostEvent(self, event)
             self.Close()
@@ -408,6 +427,37 @@
                       pos = (row, 1))
 
         #
+        # languages
+        #
+        box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Set language)"))
+        sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
+
+        gridSizer = wx.GridBagSizer (hgap = 3, vgap = 3)
+        gridSizer.AddGrowableCol(0)        
+        sizer.Add(item = gridSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 5)
+        border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
+
+        row = 0
+        gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
+                                         label = _("Choose language (requires to save and GRASS restart)::")),
+                      flag = wx.ALIGN_LEFT |
+                      wx.ALIGN_CENTER_VERTICAL,
+                      pos = (row, 0))
+        self.locales = self.settings.Get(group = 'language', key = 'locale', 
+                                    subkey = 'choices', internal = True)
+        elementList = wx.Choice(parent = panel, id = wx.ID_ANY, size = (325, -1),
+                                choices = self.locales, name = "GetSelection")
+        if self.settings.Get(group = 'language', key = 'locale', 
+                            subkey = 'lc_all'):
+            elementList.SetSelection(self.settings.Get(group = 'language', 
+                                    key = 'locale', subkey = 'lc_all'))
+        self.winId['language:locale:lc_all'] = elementList.GetId()
+
+        gridSizer.Add(item = elementList,
+                      flag = wx.ALIGN_RIGHT |
+                      wx.ALIGN_CENTER_VERTICAL,
+                      pos = (row, 1))
+        #
         # appearence
         #
         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Appearance settings"))
@@ -443,7 +493,7 @@
         #
         row += 1
         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
-                                           label = _("Menu style (requires GUI restart):")),
+                                           label = _("Menu style (requires to save and GUI restart):")),
                       flag = wx.ALIGN_LEFT |
                       wx.ALIGN_CENTER_VERTICAL,
                       pos = (row, 0))
@@ -1156,7 +1206,6 @@
             winCode.SetValue('')
             win.SetValue('')
         
-        
         try:
             win.SetValue(self.epsgCodeDict[code][1].replace('<>', '').strip())
         except KeyError:

Modified: grass/trunk/lib/init/grass.py
===================================================================
--- grass/trunk/lib/init/grass.py	2011-12-12 08:26:05 UTC (rev 49669)
+++ grass/trunk/lib/init/grass.py	2011-12-12 09:12:29 UTC (rev 49670)
@@ -240,6 +240,15 @@
     f.close()
     return kv
 
+def read_bashrc():
+    kv = {}
+    f = open(os.path.join(grass_config_dir, "bashrc"), 'r')
+    for line in f:
+        k, v = line.split(':', 1)
+        kv[k.strip()] = v.strip()
+    f.close()
+    return kv
+
 def write_gisrc(kv):
     f = open(gisrc, 'w')
     for k, v in kv.iteritems():
@@ -280,12 +289,28 @@
 def get_locale():
     global locale
     locale = None
-    for var in ['LC_ALL', 'LC_MESSAGES', 'LANG']:
-	loc = os.getenv(var)
-	if loc:
-	    locale = loc[0:2]
-	return
+    try:
+        kv = read_bashrc()
+    except:
+        kv = {}
+    if 'GRASS_LANG' in os.environ:
+        locale = os.environ['GRASS_LANG']
+        if locale[0:2] == 'en':
+          locale = None
+    elif 'GRASS_LANG' in kv:
+        locale = kv['GRASS_LANG']
+        if locale[0:2] == 'en':
+          locale = None
+    if locale:
+        for var in ['LC_ALL', 'LC_MESSAGES', 'LANG', 'LANGUAGE']:
+            os.environ[var] = locale
 
+    for var in ['LC_ALL', 'LC_MESSAGES', 'LANG', 'LANGUAGE']:
+        loc = os.getenv(var)
+        if loc:
+            locale = loc[0:2]
+    return
+
 def path_prepend(dir, var):
     path = os.getenv(var)
     if path:
@@ -817,6 +842,11 @@
     f.write("export PATH=\"%s\"\n" % os.getenv('PATH'))
     f.write("export HOME=\"%s\"\n" % userhome) # restore user home path
     
+    g7bashrc = os.path.join(grass_config_dir,'bashrc')
+    if not os.path.exists(g7bashrc):
+      fg7 = open(g7bashrc, 'w')
+      fg7.close()
+    
     for env, value in os.environ.iteritems():
         if env.find('GRASS_') < 0:
             continue



More information about the grass-commit mailing list