views:

49

answers:

1

Is there any universal method to detect the OS default language? (regardless what is the OS that is running the code)

import os
os.getenv('LANG')

The above code works under Linux, does it work under other OS?

+6  A: 

You could use the getdefaultlocale function in the locale module. It returns the language code and encoding of the system default locale in a tuple:

>>> import locale
>>> locale.getdefaultlocale()
('en_GB', 'cp1252')
Dave Webb
Thanks! Is it OS independent?
banx
@bank - Yes, I believe so. Works on Windows and the documentation describes how it works in POSIX environments so you should be fine.
Dave Webb
works for me on MS Windows and FreeBSD.
just somebody
@Dave_Webb - Works under Linux! I guess mac is considered POSIX compatible!Btw, shouldn't you update your system to be defaulted to UTF8?
banx