[GRASS-dev] locale problem solved - but have suggestion

Michael Barton Michael.Barton at asu.edu
Sun Jul 29 13:32:16 PDT 2012


A quick followup.

locale.getdefaultlocale() also needs to be changed in goutput.py. It's use in settings.py can probably stay as it is, since even with an error, it just puts "C" into the preferences key for locale until someone decides to change it.

Michael

On Jul 29, 2012, at 1:23 PM, Michael Barton wrote:

After a lot of digging I finally traced the source of the locale problem that disables the menus and a related problem that throws a lot of errors about unknown locale into the terminal.

The serious error is in python/grass/scripts/task.py line 460, and can be fixed with an error trap as follows:

    try:
        enc = locale.getdefaultlocale()[1]
    except:
        enc = None


The more general problem, however, is the use of Python's locale.getdefaultlocale() in several places. This uses system locale variables, starting with LC_CTYPE. If one of these is unrecognizable by Python for some reason, it throws an error which may just put an error message in the terminal or could cause more serious problems like the one's I've been encountering on non-English systems. This apparently has happened variously on Mac's at least.

The goal of adding a language preference in the GUI was to allow the user to set GRASS whatever language is desired. This gets set into the .grass6/wx and .grassrc6 files (and I assume .grass7/wx and .grass7/rc files too) in the GRASS LANG variable (named the same but distinct from the system LANG variable). However, the GUI then ignores this language setting by using Python's locale.getdefaultlocale() instead of reading g.gisenv LANG.

So we need to change all places that use locale.getdefaultlocale() to read the GRASS language setting with code that reads

    enc = None
    try:
        lang = grass.gisenv().get('LANG', None)
        if lang:
            enc = lang.split('.')[1]
    except:
        pass

This appears to fix all problems related to oddly set system locale variables by using the new GRASS LANG variable that is set via the GUI preferences, via g.gisenv, or manually in the .grassrc6 or .grass7/rc file.

I can do that when I'm back on my Mac set up for compiling and svn updating in a couple days unless anyone wants to do it sooner. This needs to be changed in multiple places, including gcmd.py, forms.py, task.py, utilties.py, and ghelp.py (where the code associated with locale.getdefaultlocale() just needs to be remmed out I think). It probably needs to be backported across all versions.

This Python form is also used in settings._generateLocale(), where the error raised by locale.getdefaultlocale() returns 'C'. I suppose this attempts to set a system locale setting somewhere, but I don't know where yet. My suggestion is that we not be doing this but go with the GRASS local setting to avoid problems in system default locale settings--as seems to be the intent of the new language preference.

Finally, I noticed in tracing this out that EncodeString and DecodeString are repeated in task.py and utility.py. The utility.py version can probably be deleted and replaced with the task.py version.

Michael


____________________
C. Michael Barton
Director, Center for Social Dynamics & Complexity
Professor of Anthropology, School of Human Evolution & Social Change
Arizona State University

voice:  480-965-6262 (SHESC), 480-727-9746 (CSDC)
fax:          480-965-7671 (SHESC),  480-727-0709 (CSDC)
www: http://www.public.asu.edu/~cmbarton, http://csdc.asu.edu<http://csdc.asu.edu/>












_____________________
C. Michael Barton
Visiting Scientist, Integrated Science Program
National Center for Atmospheric Research &
University Consortium for Atmospheric Research
303-497-2889 (voice)

Director, Center for Social Dynamics & Complexity
Professor of Anthropology, School of Human Evolution & Social Change
Arizona State University
www: http://www.public.asu.edu/~cmbarton, http://csdc.asu.edu<http://csdc.asu.edu/>





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20120729/1fce8daf/attachment-0001.html>


More information about the grass-dev mailing list