LANG, locale, unicode, setup.py and Debian packaging



Hello,
I hope someone can illuminate this situation for me.

Here's the nutshell:

1. On start I call locale.setlocale(locale.LC_ALL,''), the getlocale.

2. If this returns "C" or anything without 'utf8' in it, then things start
to go downhill:
2a. The app assumes unicode objects internally. i.e. Whenever there is
a "string like this" in a var it's supposed to be unicode. Whenever
something comes into the app (from a filename, a file's contents, the
command-line) it's assumed to be a byte-string that I decode("utf8") on
before placing it into my objects etc.
2b. Because of 2a and if the locale is not 'utf8 aware' (i.e. "C") I start
getting all the old 'ascii' unicode decode errors. This happens at every
string operation, at every print command and is almost impossible to fix.

3. I made the decision to check the locale and stop the app if the return
from getlocale is (None,None).

4. My setup.py (distutils) also tests locale (because it then loads gettext
to give localized information to the user during setup).

5. Because it's doing a raise SystemExit if the locale is (None,None) which
happens if LANG is set to "C", the setup.py stops.

6. Someone is helping me to package the app for Debian/Ubuntu. During the
bizarre amount of Voodoo they invoke to do that, the setup.py is being run
and it is breaking out because their LANG is set to "C"

7. I have determined, as best I can, that Python relies on LANG being set to
a proper string like en_ZA.utf8 (xx_YY.encoding) and anything else will
start Python with the default encoding of 'ascii' thus throwing the entire
app into a medieval dustbin as far as i18n goes.

8. Since I can't control the LANG of the user's system, and I am relying on
it containing 'utf8' in the locale results.. well I seem to be in a
catch-22 here.

Does anyone have some ideas? Is there a universal "proper" locale that we
could set a system to *before* the Debian build stuff starts? What would
that be - en_US.utf8?

Any words of wisdom would help.
\d

.



Relevant Pages

  • Re: LANG, locale, unicode, setup.py and Debian packaging
    ... Given that getlocale() is not to be used, what's the best way to get the ... locale later in the app? ... I need that two-letter code that's hidden in a ... typical locale like en_ZA.utf8 -- I want that 'en' part. ...
    (comp.lang.python)
  • Re: Compose key and input method
    ... But I also had some weird effects concerning the compose key. ... LANG is old style (using the old locale names), ... Old applications want LANG, new applications want LC_ALL or the above ...
    (comp.unix.solaris)
  • Re: PyGTK localisation on Win32
    ... python app.py which would translate the app into french. ... apart some quirks with LANG environment ... defaultLang, defaultEnc = locale.getdefaultlocale ... that you can not change the locale setting from the command ...
    (comp.lang.python)
  • Re: vb6 question
    ... runtime behavior to make it insensitive to system locale. ... will still interpret it on the basis of the global locale setting. ... What Rick wants/needs is a way to control that behavior for a single app ...
    (microsoft.public.vb.general.discussion)
  • Re: LANG=C not English?
    ... > feisty@feisty-laptop:~$ echo $LANG ... $ LANG=C locale ... to what English is C expected to be? ...
    (Debian-User)