First page Back Continue Last page Overview Text

Notes:


The GNU gettext1 implementation was first implemented by Sun2 in the Solaris operating system. GNU gettext allows you to internationalize a program in a “minimally invasive” fashion which requires very few changes to existing source code. Virtually all internationalized programs on Linux use GNU gettext.

It would be possible to give an entire talk on using the GNU gettext utilities. In this talk, I will limit the discussion to an overview of GNU gettext illustrating how easy it is to use, and leave many of the details as your homework assignment ;-).

Originally I had chosen “Hello, World!” for this example, but Sandra O'Donnell of the conference review board wanted something more “exciting”, so I decided to use Lewis Carroll's famous poem, The Jabberwocky3, which is of course pathologically difficult to translate4 ...

The first step is to prepare program sources. This is easy to do. First, include
the “libintl” and “locale” headers. In main(), add the calls to setlocale(), bindtextdomain(), and textdomain(). Bindtextdomain() tells the library to look for localized message catalogs for the “jabbberwocky” program in the “/usr/share/locale” directory. textdomain() sets the text domain. After that, all that is required is to wrap all translatable strings with calls to gettext().

For those of you familiar with using Trolltech's QT toolkit, you may notice that the use of gettext() is just like the use of Qobject::tr() in QT. Note however that KDE, even though it is built on top of QT, uses GNU gettext() rather than the QT linguist functions.

1. GNU gettext Utilities, http://www.gnu.org/software/gettext/manual/gettext.html. 2. Sun Microsystems, http://www.sun.com. 3. Found in Through The Looking Glass, by Lewis Carroll, first published in December, 1871. 4. Translating Jabberwocky: http://www76.pair.com/keithlim/jabberwocky/poem/hofstadter.html .