[Tutor] locale.set/getlocale asymmetry

Albert-Jan Roskam fomcl at yahoo.com
Wed Feb 20 21:56:36 CET 2013

> locale.getlocale defaults to a single category (LC_CTYPE) because of
> the parsing it does to create the tuple. The issue is that an LC_ALL
> query returns all of the categories, delimited by semicolons, if
> they're not all the same. In this case locale.getlocale(LC_ALL) raises
> a TypeError. But there's no problem using such a locale string with
> setlocale LC_ALL.
> Also, on Windows locale.getdefaultlocale uses win32 GetLocaleInfo, set
> to return ISO 639/3166 language/country codes. These codes don't work
> with the MS CRT setlocale, so locale.resetlocale fails.
> setlocale(LC_ALL, '') is supported to reset to the default. More here:

Ah, I always wondered about that. So getdefaultlocale() always returns the same as getlocale() on Linux?
Python 2.7.3 (default, Sep 26 2012, 21:53:58) [GCC 4.7.2] on linux2
>>> import locale
>>> locale.getdefaultlocale()
('en_US', 'UTF-8')
>>> locale.getlocale()
('en_US', 'UTF-8')
> setlocale
> http://msdn.microsoft.com/en-us/library/x99tb11d
> language strings
> http://msdn.microsoft.com/en-us/library/39cwe7zf
> country/region strings
> http://msdn.microsoft.com/en-us/library/cdax410z

This article [http://docs.moodle.org/dev/Table_of_locales]  specifies locales for windows (column: localewin) and other OS.
While this Unix article [http://osr507doc.sco.com/en/man/html.M/locale.M.html] has a table with old and new locale names (e.g. 
old Unix: english_uk.8859; new Unix: en_GB.ISO8859-1). And this Windows list is just like Unix [http://msdn.microsoft.com/en-us/library/39cwe7zf]

So basically, the locale specification may differ:
[A] between OS families (Unix, Windows, ...) 
[B] between OS versions (Windows XP, Windows 7, ...)? 
Woaaah, that's confusing! ISO, SIL, and IETF/BCP language codes...a dash of IANA. And the same variation for codepage defintions? These guys in Switzerland should put the 'S' back in ISO! ;-)

One additional question: when is it REALLY necessary to specify a locale variant modifier, e.g. en_US.cp1252 at euro, or perhaps the more eccentric nl_NL.cp874 at preeuro (dutch locale, thai/latin codepage ;-)

More information about the Tutor mailing list