Internationalization

gettext module

  • Provides an interface to the GNU gettext library
  • Used to internationalize applications using a database of translated strings.
     import gettext
     
     gettext.bindtextdomain("myapp","./locale")
     gettext.textdomain("myapp")
     _ = gettext.gettext 
     
     pw = getpass.getpass(_("password:"))
     if pw != correct:
          print _("Authorization failed.\n")
          raise SystemExit

General idea

  • Wrap strings to be translated by special _(...) function.
  • Use Tools/i18n/pygettext.py to extract strings into a special file
  • Modify the file by supplying translations of the strings.
  • Build a translation database using Tools/i18n/msgfmt.py and drop result in the locale directory
<<< O'Reilly OSCON 2001, New Features in Python 2, Slide 67
July 26, 2001, beazley@cs.uchicago.edu
>>>