You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
571 lines
28 KiB
571 lines
28 KiB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/doc/i18n.doc:36 -->
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
<title>Internationalization with TQt</title>
|
|
<style type="text/css"><!--
|
|
fn { margin-left: 1cm; text-indent: -1cm; }
|
|
a:link { color: #004faf; text-decoration: none }
|
|
a:visited { color: #672967; text-decoration: none }
|
|
body { background: #ffffff; color: black; }
|
|
--></style>
|
|
</head>
|
|
<body>
|
|
|
|
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
|
<tr bgcolor="#E5E5E5">
|
|
<td valign=center>
|
|
<a href="index.html">
|
|
<font color="#004faf">Home</font></a>
|
|
| <a href="classes.html">
|
|
<font color="#004faf">All Classes</font></a>
|
|
| <a href="mainclasses.html">
|
|
<font color="#004faf">Main Classes</font></a>
|
|
| <a href="annotated.html">
|
|
<font color="#004faf">Annotated</font></a>
|
|
| <a href="groups.html">
|
|
<font color="#004faf">Grouped Classes</font></a>
|
|
| <a href="functions.html">
|
|
<font color="#004faf">Functions</font></a>
|
|
</td>
|
|
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Internationalization with TQt</h1>
|
|
|
|
|
|
<p> <!-- index internationalization --><a name="internationalization"></a><!-- index i18n --><a name="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><a href="#1"> Step by Step
|
|
</a>
|
|
<ul>
|
|
<li><a href="#1-1"> Use TQString for all User-visible Text
|
|
</a>
|
|
<li><a href="#1-2"> Use tr() for all Literal Text
|
|
</a>
|
|
<li><a href="#1-3"> Use TQKeySequence() for Accelerator Values
|
|
</a>
|
|
<li><a href="#1-4"> Use TQString::arg() for Dynamic Text
|
|
</a>
|
|
<li><a href="#1-5"> Produce Translations
|
|
</a>
|
|
<li><a href="#1-6"> Support for Encodings
|
|
</a>
|
|
<li><a href="#1-7"> Localize
|
|
</a>
|
|
</ul>
|
|
<li><a href="#2"> Dynamic Translation
|
|
</a>
|
|
<li><a href="#3"> System Support
|
|
</a>
|
|
<ul>
|
|
<li><a href="#3-1"> Unix/X11
|
|
</a>
|
|
<li><a href="#3-2"> Windows
|
|
</a>
|
|
</ul>
|
|
<li><a href="#4"> Note about Locales on X11
|
|
</a>
|
|
<li><a href="#5"> Relevant TQt Classes
|
|
</a>
|
|
</ul>
|
|
<!-- endtoc -->
|
|
|
|
<p> In some cases internationalization is simple, for example, making a US
|
|
application accessible to Australian or British users may require
|
|
little more than a few spelling corrections. But to make a US
|
|
application usable by Japanese users, or a Korean application usable
|
|
by German users, will require that the software operate not only in
|
|
different languages, but use different input techniques, character
|
|
encodings and presentation conventions.
|
|
<p> TQt tries to make internationalization as painless as possible for
|
|
developers. All input widgets and text drawing methods in TQt offer
|
|
built-in support for all supported languages. The built-in font engine
|
|
is capable of correctly and attractively rendering text that contains
|
|
characters from a variety of different writing systems at the same
|
|
time.
|
|
<p> TQt supports most languages in use today, in particular:
|
|
<ul>
|
|
<li> All East Asian languages (Chinese, Japanese and Korean)
|
|
<li> All Western languages (using Latin script)
|
|
<li> Arabic
|
|
<li> Cyrillic languages (Russian)
|
|
<li> Greek
|
|
<li> Hebrew
|
|
<li> Thai and Lao
|
|
<li> All scripts in Unicode 3.2 that do not require special processing
|
|
</ul>
|
|
<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 <a href="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. <a href="ntqlineedit.html">TQLineEdit</a>, <a href="ntqtextedit.html">TQTextEdit</a>, and derived classes)
|
|
and TQt's display widgets (e.g. <a href="ntqlabel.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> <a href="ntqpainter.html#drawText">TQPainter::drawText</a>( int x, int y, const <a href="ntqstring.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 <a href="ntqrect.html">TQRect</a> since this will align in accordance with the language.
|
|
<p> <li> When you write your own text input controls, use <a href="ntqfontmetrics.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
|
|
surrounding characters. Writing input controls usually requires a
|
|
certain knowledge of the scripts it is going to be used in. Usually
|
|
the easiest way is to subclass <a href="ntqlineedit.html">TQLineEdit</a> or <a href="ntqtextedit.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 <a href="linguist-manual.html">TQt Linguist</a> manual.
|
|
<p> <h2> Step by Step
|
|
</h2>
|
|
<a name="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 <a href="ntqstring.html">TQString</a> for all User-visible Text
|
|
</h3>
|
|
<a name="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 <a href="ntqobject.html">TQObject</a> names
|
|
and file format texts) need not use TQString; the traditional
|
|
char* or the <a href="ntqcstring.html">TQCString</a> class will suffice.
|
|
<p> You're unlikely to notice that you are using Unicode;
|
|
TQString, and <a href="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>
|
|
<a name="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 <a href="ntqapplication.html#translate">TQApplication::translate</a>() function. Essentially all that is necessary
|
|
to achieve this is to use <a href="ntqobject.html#tr">TQObject::tr</a>(). For example, assuming the
|
|
<tt>LoginWidget</tt> is a subclass of TQWidget:
|
|
<p> <pre>
|
|
LoginWidget::LoginWidget()
|
|
{
|
|
<a href="ntqlabel.html">TQLabel</a> *label = new <a href="ntqlabel.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
|
|
<a href="ntqobject.html">TQObject</a> subclass, use either the tr() function of an
|
|
appropriate class, or the <a href="ntqapplication.html#translate">TQApplication::translate</a>() function
|
|
directly:
|
|
<p> <pre>
|
|
void some_global_function( LoginWidget *logwid )
|
|
{
|
|
<a href="ntqlabel.html">TQLabel</a> *label = new <a href="ntqlabel.html">TQLabel</a>(
|
|
LoginWidget::tr("Password:"), logwid );
|
|
}
|
|
|
|
void same_global_function( LoginWidget *logwid )
|
|
{
|
|
<a href="ntqlabel.html">TQLabel</a> *label = new <a href="ntqlabel.html">TQLabel</a>(
|
|
tqApp-><a href="ntqapplication.html#translate">translate</a>("LoginWidget", "Password:"),
|
|
logwid );
|
|
}
|
|
</pre>
|
|
|
|
<p> If you need to have translatable text completely
|
|
outside a function, there are two macros to help: QT_TR_NOOP()
|
|
and QT_TRANSLATE_NOOP(). They merely mark the text for
|
|
extraction by the <em>lupdate</em> utility described below.
|
|
The macros expand to just the text (without the context).
|
|
<p> Example of QT_TR_NOOP():
|
|
<pre>
|
|
TQString FriendlyConversation::greeting( int greet_type )
|
|
{
|
|
static const char* greeting_strings[] = {
|
|
QT_TR_NOOP( "Hello" ),
|
|
QT_TR_NOOP( "Goodbye" )
|
|
};
|
|
return tr( greeting_strings[greet_type] );
|
|
}
|
|
</pre>
|
|
|
|
<p> Example of QT_TRANSLATE_NOOP():
|
|
<pre>
|
|
static const char* greeting_strings[] = {
|
|
QT_TRANSLATE_NOOP( "FriendlyConversation", "Hello" ),
|
|
QT_TRANSLATE_NOOP( "FriendlyConversation", "Goodbye" )
|
|
};
|
|
|
|
TQString FriendlyConversation::greeting( int greet_type )
|
|
{
|
|
return tr( greeting_strings[greet_type] );
|
|
}
|
|
|
|
<a href="ntqstring.html">TQString</a> global_greeting( int greet_type )
|
|
{
|
|
return tqApp-><a href="ntqapplication.html#translate">translate</a>( "FriendlyConversation",
|
|
greeting_strings[greet_type] );
|
|
}
|
|
</pre>
|
|
|
|
<p> If you disable the const char* to <a href="ntqstring.html">TQString</a> automatic conversion
|
|
by compiling your software with the macro QT_NO_CAST_ASCII
|
|
defined, you'll be very likely to catch any strings you are
|
|
missing. See <a href="ntqstring.html#fromLatin1">TQString::fromLatin1</a>() for more information.
|
|
Disabling the conversion can make programming a bit cumbersome.
|
|
<p> If your source language uses characters outside Latin-1, you
|
|
might find <a href="ntqobject.html#trUtf8">TQObject::trUtf8</a>() more convenient than
|
|
<a href="ntqobject.html#tr">TQObject::tr</a>(), as tr() depends on the
|
|
<a href="ntqapplication.html#defaultCodec">TQApplication::defaultCodec</a>(), which makes it more fragile than
|
|
TQObject::trUtf8().
|
|
<p> <h3> Use <a href="ntqkeysequence.html">TQKeySequence</a>() for Accelerator Values
|
|
</h3>
|
|
<a name="1-3"></a><p> Accelerator values such as Ctrl+Q or Alt+F need to be
|
|
translated too. If you hardcode <tt>CTRL+Key_Q</tt> for "Quit" in
|
|
your application, translators won't be able to override
|
|
it. The correct idiom is
|
|
<p> <pre>
|
|
<a href="ntqpopupmenu.html">TQPopupMenu</a> *file = new <a href="ntqpopupmenu.html">TQPopupMenu</a>( this );
|
|
file-><a href="ntqmenudata.html#insertItem">insertItem</a>( tr("&Quit"), this, SLOT(quit()),
|
|
TQKeySequence(tr("Ctrl+Q", "File|Quit")) );
|
|
</pre>
|
|
|
|
<p> <h3> Use <a href="ntqstring.html#arg">TQString::arg</a>() for Dynamic Text
|
|
</h3>
|
|
<a name="1-4"></a><p> The TQString::arg() functions offer a simple means for substituting
|
|
arguments:
|
|
<pre>
|
|
void FileCopier::showProgress( int done, int total,
|
|
const <a href="ntqstring.html">TQString</a>& current_file )
|
|
{
|
|
label.setText( tr("%1 of %2 files copied.\nCopying: %3")
|
|
.arg(done)
|
|
.arg(total)
|
|
.arg(current_file) );
|
|
}
|
|
</pre>
|
|
|
|
<p> In some languages the order of arguments may need to change, and this
|
|
can easily be achieved by changing the order of the % arguments. For
|
|
example:
|
|
<pre>
|
|
<a href="ntqstring.html">TQString</a> s1 = "%1 of %2 files copied. Copying: %3";
|
|
<a href="ntqstring.html">TQString</a> s2 = "Kopierer nu %3. Av totalt %2 filer er %1 kopiert.";
|
|
|
|
<a href="ntqapplication.html#qDebug">tqDebug</a>( s1.<a href="ntqstring.html#arg">arg</a>(5).arg(10).arg("somefile.txt").ascii() );
|
|
<a href="ntqapplication.html#qDebug">tqDebug</a>( s2.<a href="ntqstring.html#arg">arg</a>(5).arg(10).arg("somefile.txt").ascii() );
|
|
</pre>
|
|
|
|
<p> produces the correct output in English and Norwegian:
|
|
<pre>
|
|
5 of 10 files copied. Copying: somefile.txt
|
|
Kopierer nu somefile.txt. Av totalt 10 filer er 5 kopiert.
|
|
</pre>
|
|
|
|
<p> <h3> Produce Translations
|
|
</h3>
|
|
<a name="1-5"></a><p> Once you are using tr() throughout an application, you can start
|
|
producing translations of the user-visible text in your program.
|
|
<p> <a href="linguist-manual.html">TQt Linguist</a>'s manual provides
|
|
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> <ol type=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 <a href="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 <a href="ntqtranslator.html#load">TQTranslator::load</a>() the translation
|
|
files appropriate for the user's language, and install them using <a href="ntqapplication.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 <a href="ntqtranslator.html">TQTranslator</a> with
|
|
<a href="ntqtranslator.html#insert">TQTranslator::insert</a>() and then writes a <tt>.qm</tt> file with
|
|
<a href="ntqtranslator.html#save">TQTranslator::save</a>(). This way the translations can come from any
|
|
source you choose.
|
|
<p> <a name="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:
|
|
<pre>
|
|
int main( int argc, char **argv )
|
|
{
|
|
<a href="ntqapplication.html">TQApplication</a> app( argc, argv );
|
|
|
|
// translation file for TQt
|
|
<a href="ntqtranslator.html">TQTranslator</a> qt( 0 );
|
|
qt.<a href="ntqtranslator.html#load">load</a>( TQString( "qt_" ) + TQTextCodec::locale(), "." );
|
|
app.<a href="ntqapplication.html#installTranslator">installTranslator</a>( &qt );
|
|
|
|
// translation file for application strings
|
|
<a href="ntqtranslator.html">TQTranslator</a> myapp( 0 );
|
|
myapp.<a href="ntqtranslator.html#load">load</a>( TQString( "myapp_" ) + TQTextCodec::locale(), "." );
|
|
app.<a href="ntqapplication.html#installTranslator">installTranslator</a>( &myapp );
|
|
|
|
...
|
|
|
|
return app.<a href="ntqapplication.html#exec">exec</a>();
|
|
}
|
|
</pre>
|
|
|
|
<p> <h3> Support for Encodings
|
|
</h3>
|
|
<a name="1-6"></a><p> The <a href="ntqtextcodec.html">TQTextCodec</a> class and the facilities in <a href="ntqtextstream.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.
|
|
<p> The application may occasionally require encodings other than the
|
|
default local 8-bit encoding. For example, an application in a
|
|
Cyrillic KOI8-R locale (the de-facto standard locale in Russia) might
|
|
need to output Cyrillic in the ISO 8859-5 encoding. Code for this
|
|
would be:
|
|
<p> <pre>
|
|
<a href="ntqstring.html">TQString</a> string = ...; // some Unicode text
|
|
|
|
<a href="ntqtextcodec.html">TQTextCodec</a>* codec = TQTextCodec::<a href="ntqtextcodec.html#codecForName">codecForName</a>( "ISO 8859-5" );
|
|
<a href="ntqcstring.html">TQCString</a> encoded_string = codec-><a href="ntqtextcodec.html#fromUnicode">fromUnicode</a>( string );
|
|
|
|
...; // use encoded_string in 8-bit operations
|
|
</pre>
|
|
|
|
<p> For converting Unicode to local 8-bit encodings, a shortcut is
|
|
available: the <a href="ntqstring.html#local8Bit">local8Bit</a>() method
|
|
of <a href="ntqstring.html">TQString</a> returns such 8-bit data. Another useful shortcut is the
|
|
<a href="ntqstring.html#utf8">utf8</a>() method, which returns text in the
|
|
8-bit UTF-8 encoding: this perfectly preserves Unicode information
|
|
while looking like plain US-ASCII if the text is wholly US-ASCII.
|
|
<p> For converting the other way, there are the <a href="ntqstring.html#fromUtf8">TQString::fromUtf8</a>() and
|
|
<a href="ntqstring.html#fromLocal8Bit">TQString::fromLocal8Bit</a>() convenience functions, or the general code,
|
|
demonstrated by this conversion from ISO 8859-5 Cyrillic to Unicode
|
|
conversion:
|
|
<p> <pre>
|
|
<a href="ntqcstring.html">TQCString</a> encoded_string = ...; // Some ISO 8859-5 encoded text.
|
|
|
|
<a href="ntqtextcodec.html">TQTextCodec</a>* codec = TQTextCodec::<a href="ntqtextcodec.html#codecForName">codecForName</a>("ISO 8859-5");
|
|
<a href="ntqstring.html">TQString</a> string = codec-><a href="ntqtextcodec.html#toUnicode">toUnicode</a>(encoded_string);
|
|
|
|
...; // Use string in all of TQt's TQString operations.
|
|
</pre>
|
|
|
|
<p> Ideally Unicode I/O should be used as this maximizes the portability
|
|
of documents between users around the world, but in reality it is
|
|
useful to support all the appropriate encodings that your users will
|
|
need to process existing documents. In general, Unicode (UTF-16 or
|
|
UTF-8) is best for information transferred between arbitrary people,
|
|
while within a language or national group, a local standard is often
|
|
more appropriate. The most important encoding to support is the one
|
|
returned by <a href="ntqtextcodec.html#codecForLocale">TQTextCodec::codecForLocale</a>(), as this is the one the user
|
|
is most likely to need for communicating with other people and
|
|
applications (this is the codec used by local8Bit()).
|
|
<p> TQt supports most of the more frequently used encodings natively. For a
|
|
complete list of supported encodings see the <a href="ntqtextcodec.html">TQTextCodec</a>
|
|
documentation.
|
|
<p> In some cases and for less frequently used encodings it may be
|
|
necessary to write your own <a href="ntqtextcodec.html">TQTextCodec</a> subclass. Depending on the
|
|
urgency, it may be useful to contact Trolltech technical support or
|
|
ask on the <tt>qt-interest</tt> mailing list to see if someone else is
|
|
already working on supporting the encoding. A useful interim measure
|
|
can be to use the <a href="ntqtextcodec.html#loadCharmapFile">TQTextCodec::loadCharmapFile</a>() function to build a
|
|
data-driven codec, although this approach has a memory and speed
|
|
penalty, especially with dynamically loaded libraries. For details of
|
|
writing your own TQTextCodec, see the main TQTextCodec class
|
|
documentation.
|
|
<p> <!-- index localization --><a name="localization"></a>
|
|
<p> <h3> Localize
|
|
</h3>
|
|
<a name="1-7"></a><p> Localization is the process of adapting to local conventions, for
|
|
example presenting dates and times using the locally preferred
|
|
formats. Such localizations can be accomplished using appropriate tr()
|
|
strings.
|
|
<p> <pre>
|
|
void Clock::setTime(const <a href="qtime.html">TQTime</a>& t)
|
|
{
|
|
if ( tr("AMPM") == "AMPM" ) {
|
|
// 12-hour clock
|
|
} else {
|
|
// 24-hour clock
|
|
}
|
|
}
|
|
</pre>
|
|
|
|
<p> In the example, for the US we would leave the translation of "AMPM" as
|
|
it is and thereby use the 12-hour clock branch; but in Europe we would
|
|
translate it as something else (anything else, e.g. "EU") and this
|
|
will make the code use the 24-hour clock branch.
|
|
<p> Localizing images is not recommended. Choose clear icons that are
|
|
appropriate for all localities, rather than relying on local puns or
|
|
stretched metaphors.
|
|
<p> <h2> Dynamic Translation
|
|
</h2>
|
|
<a name="2"></a><p> Some applications, such as TQt Linguist, must be able to support changes
|
|
to the user's language settings while they are still running. To make
|
|
widgets aware of changes to the system language, implement a public
|
|
slot called <tt>languageChange()</tt> in each widget that needs to be notified.
|
|
In this slot, you should update the text displayed by widgets using the
|
|
<a href="ntqobject.html#tr">TQObject::tr</a>(){tr()} function in the usual way; for example:
|
|
<p> <pre>
|
|
void MyWidget::languageChange()
|
|
{
|
|
titleLabel->setText(tr("Document Title"));
|
|
...
|
|
okPushButton->setText(tr("&OK"));
|
|
}
|
|
</pre>
|
|
|
|
<p> The default event handler for <a href="ntqwidget.html">TQWidget</a> subclasses responds to the
|
|
<a href="ntqevent.html#Type-enum">LanguageChange</a> event, and will call this slot
|
|
when necessary; other application components can also connect signals
|
|
to this slot to force widgets to update themselves.
|
|
<p> <h2> System Support
|
|
</h2>
|
|
<a name="3"></a><p> Some of the operating systems and windowing systems that TQt runs on
|
|
only have limited support for Unicode. The level of support available
|
|
in the underlying system has some influence on the support that TQt can
|
|
provide on those platforms, although in general TQt applications need
|
|
not be too concerned with platform-specific limitations.
|
|
<p> <h3> Unix/X11
|
|
</h3>
|
|
<a name="3-1"></a><p> <ul>
|
|
<li> Locale-oriented fonts and input methods. TQt hides these and
|
|
provides Unicode input and output.
|
|
<li> Filesystem conventions such as
|
|
<a href="http://www.ietf.org/rfc/rfc2279.txt">UTF-8</a>
|
|
are under development
|
|
in some Unix variants. All TQt file functions allow Unicode,
|
|
but convert filenames to the local 8-bit encoding, as
|
|
this is the Unix convention
|
|
(see <a href="ntqfile.html#setEncodingFunction">TQFile::setEncodingFunction</a>()
|
|
to explore alternative encodings).
|
|
<li> File I/O defaults to the local 8-bit encoding,
|
|
with Unicode options in <a href="ntqtextstream.html">TQTextStream</a>.
|
|
</ul>
|
|
<p> <h3> Windows
|
|
</h3>
|
|
<a name="3-2"></a><p> <ul>
|
|
<li> TQt provides full Unicode support, including input methods, fonts,
|
|
clipboard, drag-and-drop and file names.
|
|
<li> File I/O defaults to Latin-1, with Unicode options in TQTextStream.
|
|
Note that some Windows programs do not understand big-endian
|
|
Unicode text files even though that is the order prescribed by
|
|
the Unicode Standard in the absence of higher-level protocols.
|
|
<li> Unlike programs written with MFC or plain winlib, TQt programs
|
|
are portable between Windows 95/98 and Windows NT.
|
|
<em>You do not need different binaries to support Unicode.</em>
|
|
</ul>
|
|
<p> <h2> Note about Locales on X11
|
|
</h2>
|
|
<a name="4"></a><p> Many Unix distributions contain only partial support for some locales.
|
|
For example, if you have a <tt>/usr/share/locale/ja_JP.EUC</tt> directory,
|
|
this does not necessarily mean you can display Japanese text; you also
|
|
need JIS encoded fonts (or Unicode fonts), and the <tt>/usr/share/locale/ja_JP.EUC</tt> directory needs to be complete. For best
|
|
results, use complete locales from your system vendor.
|
|
<p> <h2> Relevant TQt Classes
|
|
</h2>
|
|
<a name="5"></a><p> These classes are relevant to internationalizing TQt applications.
|
|
|
|
<p><table width="100%">
|
|
<tr bgcolor=#f0f0f0><td><b><a href="ntqbig5codec.html">TQBig5Codec</a></b><td>Conversion to and from the Big5 encoding
|
|
<tr bgcolor=#f0f0f0><td><b><a href="ntqeucjpcodec.html">TQEucJpCodec</a></b><td>Conversion to and from EUC-JP character sets
|
|
<tr bgcolor=#f0f0f0><td><b><a href="ntqeuckrcodec.html">TQEucKrCodec</a></b><td>Conversion to and from EUC-KR character sets
|
|
<tr bgcolor=#f0f0f0><td><b><a href="ntqgb18030codec.html">TQGb18030Codec</a></b><td>Conversion to and from the Chinese GB18030/GBK/GB2312 encoding
|
|
<tr bgcolor=#f0f0f0><td><b><a href="qgb2312codec.html">TQGb2312Codec</a></b><td>Conversion to and from the Chinese GB2312 encoding
|
|
<tr bgcolor=#f0f0f0><td><b><a href="ntqgbkcodec.html">TQGbkCodec</a></b><td>Conversion to and from the Chinese GBK encoding
|
|
<tr bgcolor=#f0f0f0><td><b><a href="qhebrewcodec.html">TQHebrewCodec</a></b><td>Conversion to and from visually ordered Hebrew
|
|
<tr bgcolor=#f0f0f0><td><b><a href="ntqjiscodec.html">TQJisCodec</a></b><td>Conversion to and from JIS character sets
|
|
<tr bgcolor=#f0f0f0><td><b><a href="ntqsjiscodec.html">TQSjisCodec</a></b><td>Conversion to and from Shift-JIS
|
|
<tr bgcolor=#f0f0f0><td><b><a href="ntqtextcodec.html">TQTextCodec</a></b><td>Conversion between text encodings
|
|
<tr bgcolor=#f0f0f0><td><b><a href="qtextdecoder.html">TQTextDecoder</a></b><td>State-based decoder
|
|
<tr bgcolor=#f0f0f0><td><b><a href="qtextencoder.html">TQTextEncoder</a></b><td>State-based encoder
|
|
<tr bgcolor=#f0f0f0><td><b><a href="ntqtranslator.html">TQTranslator</a></b><td>Internationalization support for text output
|
|
<tr bgcolor=#f0f0f0><td><b><a href="qtranslatormessage.html">TQTranslatorMessage</a></b><td>Translator message and its properties
|
|
<tr bgcolor=#f0f0f0><td><b><a href="ntqtsciicodec.html">TQTsciiCodec</a></b><td>Conversion to and from the Tamil TSCII encoding
|
|
</table>
|
|
<!-- eof -->
|
|
<p><address><hr><div align=center>
|
|
<table width=100% cellspacing=0 border=0><tr>
|
|
<td>Copyright © 2007
|
|
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
|
<td align=right><div align=right>TQt 3.3.8</div>
|
|
</table></div></address></body>
|
|
</html>
|