[Tutor] How to find language name
Michael Lange
klappnase at freenet.de
Mon Oct 25 21:15:55 CEST 2004
Hello tutors,
I'm struggling here with a problem trying to determine the current language name.
I need the ISO 639 style two letter abbreviations, like 'en' for english etc.
I tried using locale.getdefaultlocale() and it seems to do just what I want:
>>> import locale
>>> locale.getdefaultlocale()
['de_DE', 'de']
>>> locale.getlocale()
['de_DE', 'ISO8859-1']
It looks like I could just do:
langName = locale.getdefaultlocale()[1]
Unfortunately the documentation for the locale module confuses me at this point:
getdefaultlocale([envvars])
Tries to determine the default locale settings and returns them as a tuple of the form (language code, encoding).
^^^^^^^^
getlocale([category])
Returns the current setting for the given locale category as sequence containing language code, encoding
^^^^^^^^
My question now, is the behavior of getdefaultlocale() platform specific, in other words, may it happen
that getdefaultlocale()[1] will be something like 'ISO8859-1' ? (BTW, my app is supposed to run on *nix systems
exclusively.)
Any hints are much appreciated. Thanks
Michael
More information about the Tutor
mailing list