6.4. Internationalization

KDE is an international product and, as such, supports multiple languages. This is accomplished very easily, with calls to the function i18n(). This function accepts a string and returns the translated string. The default language is English. You also do not need to translate internal messages. Likewise, all messages that end up with the user should be translated. This includes error messages, dialog and menubar titles, tooltips, and so on.

Generally, the syntax is i18n ("My String");

When your locale is set to en (for English), the preceding is equivalent to "My String".


   1 
   2 new QListViewItem(listview, "Item Number Six");
   3   // Wrong!
   4 new QListViewItem(listview, i18n("Item Number Six"));
   5   // Right!
   6 

This should be your course of action, even if you do not plan on internationalizing your software. Another person may volunteer, and increasing your audience is always a good thing.

Note

Don't try to create garbled messages with i18n:


   1 
   2 i18n("Couldn't open " + file + ", please check the path and try again.");
   3 

Translating such messages into other languages will not work very well, when word order issues come into play. A better idea is:


   1 
   2 i18n("Couldn't open %1, please check the path and try again.").arg(file);
   3 

When you think your program is ready for translation, you can pick up a tool such as KBabel, create the proper message files, and include them with your application.

Remember to also translate documentation files.

Another source for information on the subject can be found at the KDE Translator's and Documenter's Web site: http://i18n.kde.org.

Translation files (*.po), which can be generated with KBabel, are generally placed in the po/ directory of your package. Those .po files are produced by running the following:


   1 
   2  xgettext -C -ki18n -kI18N_NOOP \ktranslate -x$KDEDIR/include/kde.pot *.cpp
   3 

The program xgettext should be provided by the gettext package.

After the po file is produced, move it to the proper directory and open it in KBabel. Your file hierarchy should look like this:


   1 
   2 appname
   3   po
   4     fr
   5     de
   6     […]
   7   doc
   8     fr
   9     de
  10     en
  11     […]
  12   src
  13