[GRASS-dev] more on locale problem - workaround success!

Hamish hamish_b at yahoo.com
Sat Jul 28 01:08:47 PDT 2012


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


More information about the grass-dev mailing list