Portable locale usage

Laszlo Nagy gandalf at shopzeus.com
Thu Sep 8 10:41:22 CEST 2011

> I have set the system-wide locale to Croatian (Croatia)
> on my development system as instructed by:
> http://windows.microsoft.com/en-US/windows-vista/Change-the-system-locale
> Nevertheless, your proposal produces:
> ('English_United States','1252')
This is what I see on my Hungarian Windows:

Python 2.7.1 (r271:86832, Nov 27 2010, 17:19:03) [MSC v.1500 64 bit 
(AMD64)] on
Type "help", "copyright", "credits" or "license" for more information.
 >>> import locale
 >>> locale.setlocale(locale.LC_ALL, '')
 >>> locale.getlocale()
('Hungarian_Hungary', '1250')

So I'm 100% sure that the problem is with your system locale settings, 
not Python.

> Note that I would very much like
> to avoid changing the system locale
> (this requires Administrator password and system restart).
All right. But you understand, that Croatian ISO8859-2 is not supported 
on windows? So you will not be able to sort names with that under a 
windows system? (And it is not a limitation of Python.)
>> Why are you trying to force a specific locale to your program anyway?
> Because I wish to be able to correctly sort Croatian names.
Well, all right. If you want to sort Croatian names from a program that 
runs on an English (or whatever) system, then you will have to check the 
platform and use a locale that is supported by the platform. (But again, 
this is not Python's limitation. Python doesn't know what encodings are 
supported, in advance, and you cannot use a locale that is not supported...)
> I expect that most of my Windows users will not care
> to configure their computers with the national locale
> (and besides, that does not seem to work, anyway).
Croatian users will most likely use a Croatian Windows, out of the box. 
And on those systems, using locale.setlocale(locale.LC_ALL, '') will 
work perfectly. I'm not sure why it doesn't work on an English Windows 
with locale changed... I'm not a big fan of Windows, but I remember once 
I had to install a language pack for Windows before I could use a 
localized program. This might be what you need?



More information about the Python-list mailing list