[issue12964] Two improvements for the locale aliasing engine
report at bugs.python.org
Mon Sep 12 14:41:27 CEST 2011
New submission from Sinisa Segvic <sinisa.segvic at fer.hr>:
There appears to be some space for improvement
regarding the stable implementation
of the Python locale aliasing engine.
Sometimes, one wishes to be able
to override the default system locale.
For instance, it would be nice that a program
supposed to sort people according to national rules
would be able to run correctly even when the system
does not default to the national locale.
Judging from the Python manuals and
provided the desired national locale is installed,
this should be doable in at least the following two ways:
ianaLanguageSubtag='en' # the desired national locale
(ianaLanguageSubtag, locale.getpreferredencoding())) #(1)
For a quicker reference, this is
the relevant part of the manual:
If (the locale) is a tuple, it is converted
to a string using the locale aliasing engine.
The locale aliasing engine binds
the IANA language subtags to POSIX locales.
Its effects can be directly observed
>>> import locale
My first objection concerns the Windows behaviour
of the calls (1) and (2) above.
Both of the two calls *do not work* since Windows
does not recognize strings such as 'en_US.ISO8859-1'.
Instead, Windows provides their own locale nomenclature:
Consequently, the following *works*:
locale.setlocale(locale.LC_ALL, 'English_United States.1252')
IMHO this issue should be fixed, perhaps by providing
an alternate definition of the locale alias dictionary
My second objection concerns the behaviour on Linux,
where the call (1) above always works,
while (2) in some cases might not work.
It happens that the call (2)
requests an outdated 8-bit encoding
although UTF8 has obtained a world-wide acceptance.
The call shall result in a locale error
whenever the desired national locale
is present only in the UTF8 variant.
This might be fixed by changing the encodings
in the locale.locale_alias from 8-bit variants to UTF8.
Note however that the problem could be circumvented
by issuing the call (1), so this would be
less important than the Windows fix proposed above.
Source code references:
components: Library (Lib), Windows
title: Two improvements for the locale aliasing engine
versions: Python 3.2
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list