Home · All Classes · Annotated · Functions

Internationalization

Introduction

Qtopia can be translated into several languages. By default Qtopia ships only with English. Additional language-specific packages are available for purchase. For further information please contact sales@trolltech.com .

Internationalizing Qtopia software is much the same as internationalizing any Qt-based software. You should be familiar with the Qt internationalization documentation , the tr() macros, Qt Linguist and the internationalization process in general before you proceed with this document.

Translating Qtopia

Adding a translation for Qtopia is easy. There are a few steps you will need to take in order to successfully translate Qtopia into your chosen language.

  1. Install Qt 4.x (for desktops), which includes linguist, lupdate and lrelease.
  2. Run lupdate and lrelease, and start using Trolltech's linguist
  3. Add language description
  4. Translate the strings using the Linguist tool
  5. Install translation files

To translate Qtopia into an additional language you must perform the translation process described above for all the application, desktop and configuration files, and any help documentation that you wish to have available in that language.

Install Qt 4.x

You can either install Qt4 for X11 from your linux distribution, or download the Qt4 source , and compile it yourself. Once installed, you should have linguist, lupdate and lrelease tools available for you to use.

Getting Started Translating

The first step is to tell Qtopia where Qt4 is installed. This is done by setting the environment variable DQTDIR to the location of your Qt4 desktop directory. Not having set this variable will prevent that configure generates the necessary installation rules.

Qtopia ships without any translation files. If you want to generate translation files for your chosen language you have to reconfigure Qtopia:

$QPEDIR/configure -languages "ja fr zh_CN" <other configure options>

This will tell the build system that it has to build translation files for Japanese, French and Simplified Chinese.

Language Description

Create the directory $QPEDIR/i18n/<new-lang> for the new language. Qtopia will save all translation files in this directory. If this directory hasn't been created by the time the command make lupdate is executed the build system will create this directory.

Running make lupdate will generate server specific translation files(e.g. QtopiaApplications.ts which contain the translated names for Qtopia applications) in the above mentioned directory and generates translation files for each language specified via Qtopia's configure option languages. The general naming convention for these files is <appname>-<your-lang>.ts (e.g. sysinfo-zh_CN.ts).

In addition to these automatically generated files every language needs a .directory file that serves as a description for the language itself. For example, the German .directory in $QPEDIR/i18n/de looks like this:

    [Translation]
    File=QtopiaI18N
    Context=German
    [Desktop Entry]
    Name[]=German

It contains the name of the language itself as it is presented to the user. To incorporate the new .directory file into all translations it is necessary to run make lupdate for a second time. Alternatively you may create the $QPEDIR/i18n/<your-lang> directory manually, add the new .directory file and run make lupdate afterwards.

As the last step of make lupdate the script $QPEDIR/bin/nct_lupdate is executed in order to generate translation files for those strings that cannot be found in source code. This includes most config and desktop files in the $QPEDIR directory. Each of these config/desktop files must have a Translation group similar to the following one which can be found in $QPEDIR/apps/Applications/clock.desktop:

    [Translation]
    File=QtopiaApplications

This causes the generation of the file QtopiaApplications.ts in $QPEDIR/i18n/<your-lang>. If this file already exists it will be updated without the loss of any existing content.

Translating Qtopia using Linguist

The next step is to run the linguist tool. Linguist makes it easy to work with translations. It supports incremental translation, which helps you to keep track of any additional content that is added to Qtopia and needs to be translated. Any strings that are ambiguous or otherwise unclear or suspect in some way, should be translated to wahtever degree is possible and then left in the unfinished state.

For further information refer to : Linguist Manual

Installing Translation Files

The last step is to run the command make install in the Qtopia ($QPEDIR) directory. As part of this process lrelease is used to create Qt message files (.qm files).

Fonts

Qtopia uses Helvetica as the default font, however this font does not specify the characters for languages such as Chinese.

The configuration file $QPEDIR/etc/default/FontMap.conf has to be translated so that the correct font family and size is used for each language. It defines the font which can be selected by users within Qtopia. If this configuration file is empty, Qtopia will use Helvetica font as the default font. Therefore, a valid FontMap.conf and QtopiaDefaults.ts file is required to suppress Helvetica as the preferred choice. The original FontMap.conf looks like this:

    [Translation]
    File=QtopiaDefaults
    Context=FontMap
    [Map]
    Font0[]=small,helvetica,10
    Font1[]=normal,helvetica,12
    Font2[]=large,helvetica,14

Such a configuration will be suitable for most Western languages. The Map group defines three font settings that will be used by Qtopia, each of which have three parameters as follows:

  1. textual string that is presented to the user when a new setting is chosen
  2. font family specification
  3. font size.

This configuration file is marked for translation. When executing make lupdate the build system will create: $QPEDIR/i18n/<your-lang>/QtopiaDefaults.ts. Due to its special meaning, the string "small,helvetica,12" cannot be translated as a normal string, for example, a French translation may look like this:

    <name>FontMap</name>
    <message encoding="UTF-8}{
            <source>Small,helvetica,10</source>
            <translation>Petit,unifont,11</translation>
    </message>

As a result, Petit will be presented to the user and selecting this option will load the fontset unifont with a font size of 11. The chosen font has to support all characters of the given language.

Program Internationalization

When make install is executed the build system generates Qt message files (.qm files).

Placing Application Files

Application files will be placed as follows:

/opt/Qtopia/i18n/language/<appname>.qm

The language is an ISO 639 language code optionally followed by an underscore and an ISO 3166 territory (for example, "en", "en_GB", "ja", "ja_JP"). Locale suffixes are supported. For example, if your application uses British English it can have a /opt/Qtopia/i18n/en_US/<appname>.qm file specifying changes for American English. Translations with locale suffixes take precedence over translations without such suffixes.

The <appname> is the filename of the application executable.

Placing Plug-in Files

For plug-ins that are shared libraries the files must be placed in the following directory:

/opt/Qtopia/i18n/language/<pluginname>.qm

The <pluginname> is the filename of the plug-in shared object minus any extensions, but including lib if the plug-in incorporates that prefix.

Desktop & Configuration File Internationalization

Desktop/Config files (eg. /opt/Qtopia/apps/Application/<appname>.desktop) can also be translated. For example, the texteditor.desktop file begins with:

    [Translation]
    File=QtopiaApplications
    Context=Notes
    [Desktop Entry]
    Comment[]=A Text Editing Program
    Exec=textedit
    Icon=TextEditor
    Type=Application
    MimeType=text/*
    Name[]=Notes

This causes the file /opt/Qtopia/i18n/language/QtopiaApplications.qm to be loaded (if it isn't already) and the strings marked with "[]" to be translated in the "Text Editor" context. The "bin/nct_lupdate" script can be used to maintain .ts files from .desktop files.

All desktop files have to be encoded in UTF-8.

Image Translation

For certain applications it may be a requirement to translate image. A word processor application may have a tool button that markes text as bold. The button itself may have the capital letter B as image. This would not be suitable for e.g. a German user interface where the B would have to be replaced by an image displaying the letter F ('Bold' translates to the German 'Fett').

The resource system supports the following two types of translatable images:

The string i18n serves as an indicator to activate a lookup mechanism that is aware of the current user interface language. The pixmap above will be looked up in one of the following directories:

As comparison a call to QPixmap(":image/bold") will search in different directories:

A picture that requires a translation must be put into one of the i18n subfolders. American English (en_US) is used as a fall back mechanism in case there is no translation for the current language. Therefore developers who want to provide translations for their pictures have to ensure that they provide a translation/picture for American English.

Documentation Internationalization

Online documentation for applications is written in the HTML subset supported by the Qt richtext widget. Such documentation files must be placed as follows:

English documentation:

/opt/Qtopia/help/html/<appname>-suffixes.html

Non-English documentation:

/opt/Qtopia/help/<lang>/html/<appname>-suffixes.html

These files are encoded in UTF-8.

Other Internationalization Files

Other files that are language-specific are:

Translating Your Own Applications

The Qtopia build system makes it very easy to translate your own applications. The example application in $QPEDIR/examples/application summarizes what has to be done in order to generate .ts files. Further details on how to build and install additional Qtopia applications can be found in the build system help .


Copyright © 2006 Trolltech Trademarks
Qtopia 4.1.7