<tdalign="right"valign="center"><imgsrc="logo32.png"align="right"width="64"height="32"border="0"></td></tr></table><h1align=center>Internationalization with TQt</h1>
<p><!-- index internationalization --><aname="internationalization"></a><!-- index i18n --><aname="i18n"></a>
<p> The internationalization of an application is the process of making
the application usable by people in countries other than one's own.
<p><!-- toc -->
<ul>
<li><ahref="#1"> Step by Step
</a>
<ul>
<li><ahref="#1-1"> Use TQString for all User-visible Text
</a>
<li><ahref="#1-2"> Use tr() for all Literal Text
</a>
<li><ahref="#1-3"> Use TQKeySequence() for Accelerator Values
</a>
<li><ahref="#1-4"> Use TQString::arg() for Dynamic Text
</a>
<li><ahref="#1-5"> Produce Translations
</a>
<li><ahref="#1-6"> Support for Encodings
</a>
<li><ahref="#1-7"> Localize
</a>
</ul>
<li><ahref="#2"> Dynamic Translation
</a>
<li><ahref="#3"> System Support
</a>
<ul>
<li><ahref="#3-1"> Unix/X11
</a>
<li><ahref="#3-2"> Windows
</a>
</ul>
<li><ahref="#4"> Note about Locales on X11
</a>
<li><ahref="#5"> Relevant TQt Classes
</a>
</ul>
<!-- endtoc -->
<p> In some cases internationalization is simple, for example, making a US
<p> On Windows NT/2000/XP and Unix/X11 with Xft (client side font support)
the following languages are also supported:
<ul>
<li> Bengali
<li> Devanagari
<li> Dhivehi (Thaana)
<li> Gujarati
<li> Gurmukhi
<li> Kannada
<li> Khmer
<li> Malayalam (X11 only)
<li> Myanmar (X11 only)
<li> Syriac
<li> Tamil
<li> Telugu
<li> Tibetan (X11 only)
</ul>
<p> Many of these writing systems exhibit special features:
<p><ul>
<p><li><b>Special line breaking behavior.</b> Some of the Asian languages are
written without spaces between words. Line breaking can occur either
after every character (with exceptions) as in Chinese, Japanese and
Korean, or after logical word boundaries as in Thai.
<p><li><b>Bidirectional writing.</b> Arabic and Hebrew are written from right to
left, except for numbers and embedded English text which is written
left to right. The exact behavior is defined in the <ahref="http://www.unicode.org/unicode/reports/tr9/">Unicode Technical Report
#9</a>.
<p><li><b>Non spacing or diacritical marks</b> (accents or umlauts in European
languages). Some languages such as Vietnamese make extensive use of
these marks and some characters can have more than one mark at the
same time to clarify pronunciation.
<p><li><b>Ligatures.</b> In special contexts, some pairs of characters get
replaced by a combined glyph forming a ligature. Common examples are
the fl and fi ligatures used in typesetting US and European books.
<p></ul>
<p> TQt tries to take care of all the special features listed above. You
usually don't have to worry about these features so long as you use
TQt's input widgets (e.g. <ahref="qlineedit.html">TQLineEdit</a>, <ahref="qtextedit.html">TQTextEdit</a>, and derived classes)
and TQt's display widgets (e.g. <ahref="qlabel.html">TQLabel</a>).
<p> Support for these writing systems is transparent to the programmer
and completely encapsulated in TQt's text engine. This means that you
don't need to have any knowledge about the writing system used in a
particular language, except for the following small points:
<ul>
<p><li><ahref="qpainter.html#drawText">TQPainter::drawText</a>( int x, int y, const <ahref="qstring.html">TQString</a>&str ) will always
draw the string with it's left edge at the position specified with
the x, y parameters. This will usually give you left aligned strings.
Arabic and Hebrew application strings are usually right
aligned, so for these languages use the version of drawText() that
takes a <ahref="qrect.html">TQRect</a> since this will align in accordance with the language.
<p><li> When you write your own text input controls, use <ahref="qfontmetrics.html#charWidth">TQFontMetrics::charWidth</a>() to determine the width of a character in a
string. In some languages (e.g. Arabic or languages from the Indian
subcontinent), the width and shape of a glyph changes depending on the
certain knowledge of the scripts it is going to be used in. Usually
the easiest way is to subclass <ahref="qlineedit.html">TQLineEdit</a> or <ahref="qtextedit.html">TQTextEdit</a>.
<p></ul>
<p> The following sections give some information on the status
of the internationalization (i18n) support in TQt.
<p> See also the <ahref="linguist-manual.html">TQt Linguist</a> manual.
<p><h2> Step by Step
</h2>
<aname="1"></a><p> Writing multi-platform international software with TQt is a gentle,
incremental process. Your software can become internationalized in
the following stages:
<p><h3> Use <ahref="qstring.html">TQString</a> for all User-visible Text
</h3>
<aname="1-1"></a><p> Since TQString uses the Unicode encoding internally, every
language in the world can be processed transparently using
familiar text processing operations. Also, since all TQt
functions that present text to the user take a TQString as a
parameter, there is no char* to TQString conversion overhead.
<p> Strings that are in "programmer space" (such as <ahref="qobject.html">TQObject</a> names
and file format texts) need not use TQString; the traditional
char* or the <ahref="qcstring.html">TQCString</a> class will suffice.
<p> You're unlikely to notice that you are using Unicode;
TQString, and <ahref="qchar.html">TQChar</a> are just like easier versions of the crude
const char* and char from traditional C.
<p><h3> Use tr() for all Literal Text
</h3>
<aname="1-2"></a><p> Wherever your program uses <tt>"quoted text"</tt> for text that will
be presented to the user, ensure that it is processed by the <ahref="qapplication.html#translate">TQApplication::translate</a>() function. Essentially all that is necessary
to achieve this is to use <ahref="qobject.html#tr">TQObject::tr</a>(). For example, assuming the
<tt>LoginWidget</tt> is a subclass of TQWidget:
<p><pre>
LoginWidget::LoginWidget()
{
<ahref="qlabel.html">TQLabel</a> *label = new <ahref="qlabel.html">TQLabel</a>( tr("Password:"), this );
...
}
</pre>
<p> This accounts for 99% of the user-visible strings you're likely to
write.
<p> If the quoted text is not in a member function of a
<ahref="qobject.html">TQObject</a> subclass, use either the tr() function of an
appropriate class, or the <ahref="qapplication.html#translate">TQApplication::translate</a>() function
directly:
<p><pre>
void some_global_function( LoginWidget *logwid )
{
<ahref="qlabel.html">TQLabel</a> *label = new <ahref="qlabel.html">TQLabel</a>(
LoginWidget::tr("Password:"), logwid );
}
void same_global_function( LoginWidget *logwid )
{
<ahref="qlabel.html">TQLabel</a> *label = new <ahref="qlabel.html">TQLabel</a>(
further information about TQt's translation tools, <em>TQt Linguist</em>, <em>lupdate</em> and <em>lrelease</em>.
<p> Translation of a TQt application is a three-step process:
<p><oltype=1>
<p><li> Run <em>lupdate</em> to extract translatable text from the C++ source
code of the TQt application, resulting in a message file for
translators (a <tt>.ts</tt> file). The utility recognizes the tr() construct
and the QT_*_NOOP macros described above and produces <tt>.ts</tt> files
(usually one per language).
<p><li> Provide translations for the source texts in the <tt>.ts</tt> file, using
<em>TQt Linguist</em>. Since <tt>.ts</tt> files are in XML format, you can also
edit them by hand.
<p><li> Run <em>lrelease</em> to obtain a light-weight message file (a <tt>.qm</tt>
file) from the <tt>.ts</tt> file, suitable only for end use. Think of the <tt>.ts</tt> files as "source files", and <tt>.qm</tt> files as "object files". The
translator edits the <tt>.ts</tt> files, but the users of your application
only need the <tt>.qm</tt> files. Both kinds of files are platform and
locale independent.
<p></ol>
<p> Typically, you will repeat these steps for every release of your
application. The <em>lupdate</em> utility does its best to reuse the
translations from previous releases.
<p> Before you run <em>lupdate</em>, you should prepare a project file. Here's
an example project file (<tt>.pro</tt> file):
<p><pre>
HEADERS = funnydialog.h \
wackywidget.h
SOURCES = funnydialog.cpp \
main.cpp \
wackywidget.cpp
FORMS = fancybox.ui
TRANSLATIONS = superapp_dk.ts \
superapp_fi.ts \
superapp_no.ts \
superapp_se.ts
</pre>
<p> When you run <em>lupdate</em> or <em>lrelease</em>, you must give the name of the
project file as a command-line argument.
<p> In this example, four exotic languages are supported: Danish, Finnish,
Norwegian and Swedish. If you use <ahref="qmake-manual.html">qmake</a>, you usually don't need an extra project
file for <em>lupdate</em>; your <tt>qmake</tt> project file will work fine once
you add the <tt>TRANSLATIONS</tt> entry.
<p> In your application, you must <ahref="qtranslator.html#load">TQTranslator::load</a>() the translation
files appropriate for the user's language, and install them using <ahref="qapplication.html#installTranslator">TQApplication::installTranslator</a>().
<p> If you have been using the old TQt tools (<tt>findtr</tt>, <tt>msg2qm</tt> and <tt>mergetr</tt>), you can use <em>qm2ts</em> to convert your old <tt>.qm</tt> files.
<p><em>linguist</em>, <em>lupdate</em> and <em>lrelease</em> are installed in the <tt>bin</tt>
subdirectory of the base directory TQt is installed into. Click Help|Manual
in <em>TQt Linguist</em> to access the user's manual; it contains a tutorial
to get you started.
<p> While these utilities offer a convenient way to create <tt>.qm</tt> files,
any system that writes <tt>.qm</tt> files is sufficient. You could make an
application that adds translations to a <ahref="qtranslator.html">TQTranslator</a> with
<ahref="qtranslator.html#insert">TQTranslator::insert</a>() and then writes a <tt>.qm</tt> file with
<ahref="qtranslator.html#save">TQTranslator::save</a>(). This way the translations can come from any
source you choose.
<p><aname="qt-itself"></a>
TQt itself contains over 400 strings that will also need to be
translated into the languages that you are targeting. You will find
translation files for French and German in <tt>$QTDIR/translations</tt> as
well as a template for translating to other languages. (This directory
also contains some additional unsupported translations which may be
useful.)
<p> Typically, your application's main() function will look like this:
<aname="1-6"></a><p> The <ahref="qtextcodec.html">TQTextCodec</a> class and the facilities in <ahref="qtextstream.html">TQTextStream</a> make it easy to
support many input and output encodings for your users' data. When an
application starts, the locale of the machine will determine the 8-bit
encoding used when dealing with 8-bit data: such as for font
selection, text display, 8-bit text I/O and character input.