Portable locale usage

ssegvic sinisa.segvic at fer.hr
Wed Sep 7 12:39:14 CEST 2011

On 6 ruj, 17:53, Thomas Jollans <t... at jollybox.de> wrote:
> On 06/09/11 16:46, ssegvic wrote:
> > For the moment, I only wish to properly sort a Croatian text file
> > both on Windows and Linux (I am a cautious guy, I like reachable
> > goals).
> > When the locale is properly set, sorting works like a charm
> > with mylist.sort(key=locale.strxfrm).
> The problem with that is of course that a Croatian locale has to be
> installed. Many Linux systems don't have locales that aren't used.

It appears we did not understand each other completely.

Python locales on Linux work as advertised,
I have no problems with locales on Linux whatsoever
(yes, the Croatian locale had to be manually installed).

On the other hand, it appears that
Python locales on Windows do not work as advertised.
Consider for instance my initial example:
  locale.setlocale(locale.LC_ALL, ('hr',
The code above does not work on Windows even though the fine manual
locale.setlocale(category, locale=None)
  If (the locale) is a tuple, it is converted to a string using the
locale aliasing engine.
I do not believe my troubles could be solved by installing anything,
since the OS support for Croatian apperas to be present:
  locale.setlocale(locale.LC_ALL, 'Croatian_Croatia.1250')

To conclude, it seems to me that the Windows implementation
of the locale aliasing engine has some space for improvement.

All further comments shall be greatly appreciated :-)



More information about the Python-list mailing list