Annex B. Localization : Translation
The translation framework most commonly used in FOSS is GNU gettext, although some cross-platform FOSS, such as AbiWord, Mozilla and OpenOffice.org use their own frameworks as a result of the cross-platform abstractions. In this section, the GNU gettext, which covers more than 90 percent of GNU/Linux desktops, is discussed briefly. The concepts discussed here, however, apply to other frameworks.
Messages in program source code are put in a short macro that calls a gettext function to retrieve the translated version. At program initialization, the hashed message database corresponding to LC_MESSAGES locale category is loaded. Then, all messages covered by the macros are translated by quick lookup during program execution. Therefore, the task of translation is to build the message translation database for a particular language and get it installed in an appropriate place for the locale. With that preparation, the gettext programs are automatically translated as per locale setting without having to touch the source code.
GNU gettext also provides tools for creating the message database. Two kinds of files are involved in the process:
- PO (Portability Object) file. This is a file in human-readable form for the translators to work with. It is named so because of its plain-text nature, which makes it portable to other platforms.
- MO (Machine Object) file. This is a hashed database for machines to read. It is in the final format to be loaded by the gettext program. There are many translation frameworks in commercial Unices, and these MO files are not compatible. One may also find some GMO files as immediate output from GNU gettext tools. They are MO files containing some GNU gettext enhanced features.
Important GNU gettext tools will be discussed by describing the summarized steps of translation from scratch (See Figure 3):
- Extract messages with the xgettext utility. What you get is the �package.pot� file as a template for the PO file.
- Create the PO file for your language from the template, either by copying it to �xx.po� (where xx is your locale language) and filling its header information with your information, or by using the msginit utility.
- Translate the messages by editing the PO file with your favourite text editor. Some specialized editors for PO files, such as kbabel and gtranslator, are also available.
- Convert the PO file into MO file using the msgfmt utility.
- Install the MO file under the LC_MESSAGES directory of your locale.
- When the program develops, new strings are introduced. You need not begin from scratch again. Rather, you extract the new PO template with the xgettext utility as usual, and then merge the template with your current PO with the msgmerge utility. Then, you can continue by translating the new messages.
GNOME intltool
GNU/Linux desktops have more things to translate than messages in C/C++ source code. The system menu entries, lists of sounds on events, for example, also contain messages, mostly in XML formats that are not supported by GNU gettext. One may dig into these individual files to translate the messages, but this is very inconvenient to maintain and is also error prone.
KDE has a strong policy for translation. PO files for all KDE core applications are extracted into a single directory for each language, so that translators can work in a single place to translate the desktop without a copy of the source code. But in practice, one needs to look into the sources occasionally to verify the exact meaning of some messages, especially error messages. This already includes all the messages outside the C++ sources mentioned above.
GNOME comes up with a different approach. The PO files are still placed in the source under the 'po' subdirectory as usual. But instead of directly using xgettext to extract messages from the source, the GNOME project has developed an automatic tool called intltool. This tool extracts messages from the XML files into the PO template along with the usual things xgettext does, and merges the translations back as well. As a result, despite the heterogeneous translation system, what translators need to do is still edit a single PO file for a particular language.
The use of intltool is easy. To generate a PO template, change the directory to the 'po' subdirectory and run:
$ intltool-update �-pot
To generate a new PO file and merge with existing translation:
$ intltool-update xx
where xx is the language code. That is all that is required. Editing the PO file as usual can then begin.
When PO editing is complete, the usual installation process of typical GNOME sources will automatically call the appropriate intltool command to merge the translations back into those XML files before installing. Note that, with this automated system, one should not directly call the xgettext and msgmerge commands any more.
The following sites and documents provide more information on KDE and GNOME translation:
- KDE Internationalization Home (i18n.kde.org/)
- The KDE Translation HOWTO (i18n.kde.org/translation-howto/)
- The GNOME Translation Project (developer.gnome.org/projects/gtp/)
- Localizing GNOME Applications (developer.gnome.org/projects/gtp/l10n-guide/)
- How to Use GNOME CVS as a Translator (developer.gnome.org/doc/tutorials/gnome-i18n/translator.html)
PO Editors
A PO file is a plain text file. This can be edited, using a favourite text editor. But, as stated earlier, translation is a labour-intensive task. It is worth considering some convenient tools to speed up the job.
Normally, the editor is needed to be able to edit UTF-8, as both KDE and GNOME now have used it as standard text encoding. However, the following tools have many other features.
- KBabel
Part of the KDE Software Development Kit, KBabel is an advanced and easy-to-use PO-files editor with full navigation and editing capabilities, syntax checking and statistics. The editor separates translated, un-translated and fuzzy messages so that it is easy to find and edit the unfinished parts.
KBabel also provides CatalogManager, which allows keeping track of many PO-files at once, and KBabelDict for keeping the glossary, which is important for translation consistency, especially among team members from different backgrounds.
- Gtranslator
Gtranslator is the PO-file editor for the GNOME desktop. It is very similar to Kbabel in core functionality.
Gtranslator also supports auto-translation, where translations are learnt and transferred into its memory, and can be applied in later translations using a hot key.

Post new comment