[Tutor] How to find language name

Liam Clarke cyresse at gmail.com
Tue Oct 26 01:53:38 CEST 2004


Hi Michael,

quoted from docs ---
To maintain compatibility with other platforms, not only the LANG
variable is tested, but a list of variables given as envvars
parameter. The first found to be defined will be used. envvars
defaults to the search path used in GNU gettext; it must always
contain the variable name "LANG". The GNU gettext search path contains
'LANGUAGE', 'LC_ALL', 'LC_CTYPE', and 'LANG', in that order.


Unless I'm wrong, and someone will let me know very shortly if I am;
the returned tuple from  getdefaultlocale will always be (language
code, encoding)

Regards,

Liam Clarke


On Mon, 25 Oct 2004 21:15:55 +0200, Michael Lange <klappnase at freenet.de> wrote:
> 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
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.


More information about the Tutor mailing list