[GRASS-dev] more on locale problem - workaround success!
Michael Barton
Michael.Barton at asu.edu
Sat Jul 28 09:56:45 PDT 2012
This remains puzzling. On my MacBook with Lion, I have the following:
Michaels-MacBook-Air:~ cmbarton$ echo $LC_CTYPE
Michaels-MacBook-Air:~ cmbarton$ echo $LC_ALL
Michaels-MacBook-Air:~ cmbarton$ echo $LANG
en_US.UTF-8
Michaels-MacBook-Air:~ cmbarton$ echo $LC_MESSAGE
Michaels-MacBook-Air:~ cmbarton$ python
Python 2.7.1 (r271:86832, Jun 25 2011, 05:09:01)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getdefaultlocale()
('en_US', 'UTF8')
On Carlos' MacBook with Lion (without setting LC_CTYPE in .profile), we get the following:
MacBook-Pro-de-Carlos:~ carlosrodriguezrellan$ echo $LC_CTYPE
UTF-8
MacBook-Pro-de-Carlos:~ carlosrodriguezrellan$ echo $LC_ALL
MacBook-Pro-de-Carlos:~ carlosrodriguezrellan$ echo $LANG
MacBook-Pro-de-Carlos:~ carlosrodriguezrellan$ echo $LC_MESSAGE
MacBook-Pro-de-Carlos:~ carlosrodriguezrellan$ python
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getdefaultlocale()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 496, in getdefaultlocale
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 428, in _parse_localename
ValueError: unknown locale: UTF-8
So by default, my LANG is set but none of the other locale variables are set. For Carlos, LC_CTYPE is set (incorrectly??) and nothing else (including LANG) is set.
Neither one of us have explicitly set any of these locale variables prior to hitting this issue. Since another Spanish colleague (Agustin) also reported problems, I wonder if this is something that is "normal" for Spanish-enabled Macs.
An error trap on locale.getdefaultlocale() and setting the language explicitly in wx (rather than depending on the system locale variables), as I think the intent is, would fix this problem.
Adding an error trap to locale.getdefaultlocale() is easy (I would use try/except); fixing the GUI to use the wx configuration file instead of .grassrc6 is somewhat more labor.
MIchael
On Jul 28, 2012, at 1:08 AM, Hamish wrote:
> Michael wrote:
>> So I think there needs to be an error trap at this point for
>> "locale.getdefaultlocale()" and a default fallback to
>> English.
>
> perhaps better, fall back to "C" aka unset.
>
> fwiw, on linux with python 2.4.4 and 2.6.6, 2.7.3, all give:
>
>>>> import locale
>>>> locale.getdefaultlocale()
> (None, None)
>>>> lang = '.'.join(locale.getdefaultlocale())
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: sequence item 0: expected string, NoneType found
>>>>
>
> when the parent shell has LANG=C set.
>
> with LANG=en_US.UTF-8 at the shell, the above gives:
> locale.getdefaultlocale() = ('en_US', 'UTF-8')
> lang = 'en_US.UTF-8'
>
>
> the tuple it returns is (language code, encoding).
> http://docs.python.org/library/locale.html
>
> perhaps add something like:
> if locale.getdefaultlocale()[0] is None:
> lang = None
> else:
> lang = '.'.join(locale.getdefaultlocale())
>
>
> note,
> http://stackoverflow.com/questions/955986/what-is-the-correct-way-to-set-pythons-locale
>
> so fallback to a common language setting may also have to be platform
> dependent. dunno what Windows makes of LANG=C.
>
>
>> One thing that I notice is that nothing seems to be
>> reading the language setting in the wx file, where
>> preferences sets it. I thought the idea was to make this a
>> GUI preference. So perhaps, this also needs to be changed to
>> read the preferences file instead of .grassrc6.
>
> sounds reasonable to me, but I wasn't following along & have not
> heard it described how the new system is supposed to work.
>
>
> thanks for looking into this,
> Hamish
_____________________
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
More information about the grass-dev
mailing list