Contents Up Previous Next

Internationalization

Although internationalization of an application (i18n for short) involves far more than just translating its text messages to another message -- date, time and currency formats need changing too, some languages are written left to right and others right to left, character encoding may differ and many other things may need changing too -- it is a necessary first step. wxWidgets provides facilities for message translation with its wxLocale class and is itself fully translated into several languages. Please consult wxWidgets home page for the most up-to-date translations - and if you translate it into one of the languages not done yet, your translations would be gratefully accepted for inclusion into the future versions of the library!

The wxWidgets approach to i18n closely follows GNU gettext package. wxWidgets uses the message catalogs which are binary compatible with gettext catalogs and this allows to use all of the programs in this package to work with them. But note that no additional libraries are needed during the run-time, however, so you have only the message catalogs to distribute and nothing else.

During program development you will need the gettext package for working with message catalogs. Warning: gettext versions < 0.10 are known to be buggy, so you should find a later version of it!

There are two kinds of message catalogs: source catalogs which are text files with extension .po and binary catalogs which are created from the source ones with msgfmt program (part of gettext package) and have the extension .mo. Only the binary files are needed during program execution.

The program i18n involves several steps:

  1. Translating the strings in the program text using wxGetTranslation or equivalently the _() macro.
  2. Extracting the strings to be translated from the program: this uses the work done in the previous step because xgettext program used for string extraction recognises the standard _() as well as (using its -k option) our wxGetTranslation and extracts all strings inside the calls to these functions. Alternatively, you may use -a option to extract all the strings, but it will usually result in many strings being found which don't have to be translated at all. This will create a text message catalog -- a .po file.
  3. Translating the strings extracted in the previous step to other language(s). It involves editing the .po file.
  4. Compiling the .po file into .mo file to be used by the program.
  5. Setting the appropriate locale in your program to use the strings for the given language: see wxLocale.

See also the GNU gettext documentation linked from docs/html/index.htm in your wxWidgets distribution.

See also Writing non-English applications. It focuses on handling charsets related problems.

Finally, take a look at the i18n sample which shows to you how all this looks in practice.