Multilingual programs under Linux generally use the GNU gettext system which provides a set of tools for both the programmer and the translator. The two of them can work independently of each other, and the particular message output by the program will depend on the locale (see Sec. 4) that is in effect at the time the program is run. Instead of directly using C library routines for output, the program uses a gettext wrapper, viz., instead of,
#include <stdio.h>
int main(void) {
printf( ``Hello world!\n'' );
return 0;
}
she would write:
#include <stdio.h>
#include <libintl.h>
int main(void) {
setlocale( LC_ALL, "" );
textdomain( ``hello-world'' );
printf( gettext( ``Hello, world!\n'' ) );
return 0;
}
The modicum of extra typing here can be further simplified by the use of a CPP
macro to replace the string ``gettext'' in the program source code. The
strings needing translation can then be extracted from the source code by
xgettext leading to an editable .pot (portable object template) file. At
this point, no translations have yet been made, and the template file is not
yet oriented towards any particular language.
The translator, working independently of the programmer, can then add translated messages using the .pot template to create a LANG.po file, specific to a particular language. This task is simplified somewhat by using PO mode in emacs.
A portable object file must be compiled into a .mo (machine object) file with the msgfmt program before it can be used. Finally, the .mo file is copied to a standard location, usually /usr/share/locale/LL/LC_MESSAGES or /usr/share/locale/LL_CC/LC_MESSAGES, where LL stands for a language, and CC for a country, e.g., for Oriya, the location might be /usr/share/locale/or_IN/LC_MESSAGES. The translated message is picked from the appropriate message catalogue depending on the locale that is in effect at the time of running the program. E.g., if the locale is set to es, the messages would be taken from the program's .mo file in /usr/share/locale/es/LC_MESSAGES, and if it is set instead to or_IN, the .mo file in /usr/share/locale/or_IN/LC_MESSAGES would be used.
While this is the basic scheme, further complications are introduced by the need to update the internationalized messages as the program source is modified. The gettext manual provides a complete description of the process of internationalization and translation, and is available, e.g., in emacs info-mode (accessed by typing Control-h i in emacs). A more extensive introduction to the work of translation using gettext is also available [50].
Gora Mohanty 2004-07-24