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 future versions of the library!
The wxWidgets approach to i18n closely follows the 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 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.
Translating your application involves several steps:
xgettextprogram used for string extraction recognises the standard
_()as well as (using its
-koption) our wxGetTranslation and extracts all strings inside the calls to these functions. Alternatively, you may use
-aoption 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.
The .mo files with compiled catalogs must be included with the application. By default, wxFileTranslationsLoader is used to load them from files installed alongside the application (although you could use wxResourceTranslationsLoader or some custom loader too).
The files are expected to be in the resources directory (as returned by wxStandardPaths::GetLocalizedResourcesDir(wxStandardPaths::ResourceCat_Messages). If the message catalogs are not installed in this default location you may explicitly use wxFileTranslationsLoader::AddCatalogLookupPathPrefix() to still allow wxWidgets to find them, but it is recommended to use the default locations when possible.
Depending on the platform, the default location differs. On Windows, it is alongside the executable. On Unix, translations are expected to be in "$prefix/share/locale". On OS X, application bundle's Resources subdirectory is used.
In all cases, translations are searched for in subdirectories named using the languages codes from ISO 639. The .mo file(s) should be located either directly in that directory or in LC_MESSAGES subdirectory. On OS X, ".lproj" extension is used for the per-languages Resources subdirectories.
Here's how an app would typically install the files on Unix:
And on OS X:
And on Windows:
It is of course possible to use the Unix layout everywhere instead.
If you translate the accelerator modifier names (Ctrl, Alt and Shift) in your menu labels, you may find the accelerators no longer work. In your message catalogs, you need to provide individual translations of these modifiers from their lower case names (ctrl, alt, shift) so that the wxWidgets accelerator code can recognise them even when translated. wxWidgets does not provide translations for all of these currently. wxWidgets does not yet handle translated special key names such as Backspace, End, Insert, etc.