Python-Ref > GUI programming with PyGTK > Localization using gettext > Language detection on Windows


Language detection on Windows

The automatic detection of language in gettext uses the system environment vriables to detect the desired localization. However, on Windows systems this method of language selection is not used and therefore gettext cannot detect the systems language properly. To help it, we need to supply the proper environment variable "by hand". The following code snippet shows how:
  1   import gettext
  2   import locale
  3   import os
  5   # get the default locale using the locale module
  6   default_lang, default_enc = locale.getdefaultlocale()
  7   # if found, set the appropriate environment variable
  8   if default_lang:
  9     print "Default language is:", default_lang
 10     os.environ['LANG'] = default_lang
 12   # from here, everything works as before
 13   gettext.install( "my_example", "./", False)
 14   print _( "Hello world.")
Default language is: en_US
Hello world.
Doba běhu: 20.2 ms