source: trunk/doc/src/internationalization/i18n.qdoc@ 968

Last change on this file since 968 was 846, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 31.3 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the documentation of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:FDL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in a
14** written agreement between you and Nokia.
15**
16** GNU Free Documentation License
17** Alternatively, this file may be used under the terms of the GNU Free
18** Documentation License version 1.3 as published by the Free Software
19** Foundation and appearing in the file included in the packaging of this
20** file.
21**
22** If you have questions regarding the use of this file, please contact
23** Nokia at [email protected].
24** $QT_END_LICENSE$
25**
26****************************************************************************/
27
28/*!
29 \group i18n
30 \title Qt Classes for Internationalization
31
32 See \l{Internationalization with Qt} for information on how to use these classes
33 in your applications.
34*/
35
36/*!
37 \page internationalization.html
38 \title Internationalization with Qt
39 \brief Information about Qt's support for internationalization and multiple languages.
40 \nextpage Writing Source Code for Translation
41
42 \ingroup qt-basic-concepts
43
44 \keyword internationalization
45 \keyword i18n
46
47 The internationalization of an application is the process of making
48 the application usable by people in countries other than one's own.
49
50 \tableofcontents
51
52 \section1 Relevant Qt Classes and APIs
53
54 These classes support internationalizing of Qt applications.
55
56 \annotatedlist i18n
57
58 \section1 Languages and Writing Systems
59
60 In some cases internationalization is simple, for example, making a US
61 application accessible to Australian or British users may require
62 little more than a few spelling corrections. But to make a US
63 application usable by Japanese users, or a Korean application usable
64 by German users, will require that the software operate not only in
65 different languages, but use different input techniques, character
66 encodings and presentation conventions.
67
68 Qt tries to make internationalization as painless as possible for
69 developers. All input widgets and text drawing methods in Qt offer
70 built-in support for all supported languages. The built-in font engine
71 is capable of correctly and attractively rendering text that contains
72 characters from a variety of different writing systems at the same
73 time.
74
75 Qt supports most languages in use today, in particular:
76 \list
77 \o All East Asian languages (Chinese, Japanese and Korean)
78 \o All Western languages (using Latin script)
79 \o Arabic
80 \o Cyrillic languages (Russian, Ukrainian, etc.)
81 \o Greek
82 \o Hebrew
83 \o Thai and Lao
84 \o All scripts in Unicode 5.1 that do not require special processing
85 \endlist
86
87 On Windows, Unix/X11 with FontConfig (client side font support)
88 and Qt for Embedded Linux the following languages are also supported:
89 \list
90 \o Bengali
91 \o Devanagari
92 \o Dhivehi (Thaana)
93 \o Gujarati
94 \o Gurmukhi
95 \o Kannada
96 \o Khmer
97 \o Malayalam
98 \o Myanmar
99 \o Syriac
100 \o Tamil
101 \o Telugu
102 \o Tibetan
103 \o N'Ko
104 \endlist
105
106 Many of these writing systems exhibit special features:
107
108 \list
109
110 \o \bold{Special line breaking behavior.} Some of the Asian languages are
111 written without spaces between words. Line breaking can occur either
112 after every character (with exceptions) as in Chinese, Japanese and
113 Korean, or after logical word boundaries as in Thai.
114
115 \o \bold{Bidirectional writing.} Arabic and Hebrew are written from right to
116 left, except for numbers and embedded English text which is written
117 left to right. The exact behavior is defined in the
118 \l{http://www.unicode.org/unicode/reports/tr9/}{Unicode Technical Annex #9}.
119
120 \o \bold{Non-spacing or diacritical marks (accents or umlauts in European
121 languages).} Some languages such as Vietnamese make extensive use of
122 these marks and some characters can have more than one mark at the
123 same time to clarify pronunciation.
124
125 \o \bold{Ligatures.} In special contexts, some pairs of characters get
126 replaced by a combined glyph forming a ligature. Common examples are
127 the fl and fi ligatures used in typesetting US and European books.
128
129 \endlist
130
131 Qt tries to take care of all the special features listed above. You
132 usually don't have to worry about these features so long as you use
133 Qt's input widgets (e.g. QLineEdit, QTextEdit, and derived classes)
134 and Qt's display widgets (e.g. QLabel).
135
136 Support for these writing systems is transparent to the
137 programmer and completely encapsulated in \l{rich text
138 processing}{Qt's text engine}. This means that you don't need to
139 have any knowledge about the writing system used in a particular
140 language, except for the following small points:
141
142 \list
143
144 \o QPainter::drawText(int x, int y, const QString &str) will always
145 draw the string with its left edge at the position specified with
146 the x, y parameters. This will usually give you left aligned strings.
147 Arabic and Hebrew application strings are usually right
148 aligned, so for these languages use the version of drawText() that
149 takes a QRect since this will align in accordance with the language.
150
151 \o When you write your own text input controls, use QTextLayout.
152 In some languages (e.g. Arabic or languages from the Indian
153 subcontinent), the width and shape of a glyph changes depending on the
154 surrounding characters, which QTextLayout takes into account.
155 Writing input controls usually requires a certain knowledge of the
156 scripts it is going to be used in. Usually the easiest way is to
157 subclass QLineEdit or QTextEdit.
158
159 \endlist
160
161 The following sections give some information on the status of the
162 internationalization (i18n) support in Qt. See also the \l{Qt
163 Linguist manual}.
164
165 \section1 Step by Step
166
167 Writing cross-platform international software with Qt is a gentle,
168 incremental process. Your software can become internationalized in
169 the following stages:
170
171 \section2 Use QString for All User-Visible Text
172
173 Since QString uses the Unicode 5.1 encoding internally, every
174 language in the world can be processed transparently using
175 familiar text processing operations. Also, since all Qt functions
176 that present text to the user take a QString as a parameter,
177 there is no \c{char *} to QString conversion overhead.
178
179 Strings that are in "programmer space" (such as QObject names
180 and file format texts) need not use QString; the traditional
181 \c{char *} or the QByteArray class will suffice.
182
183 You're unlikely to notice that you are using Unicode;
184 QString, and QChar are just like easier versions of the crude
185 \c{const char *} and char from traditional C.
186
187 \section2 Use tr() for All Literal Text
188
189 Wherever your program uses "quoted text" for text that will
190 be presented to the user, ensure that it is processed by the \l
191 QCoreApplication::translate() function. Essentially all that is necessary
192 to achieve this is to use QObject::tr(). For example, assuming the
193 \c LoginWidget is a subclass of QWidget:
194
195 \snippet doc/src/snippets/code/doc_src_i18n.qdoc 0
196
197 This accounts for 99% of the user-visible strings you're likely to
198 write.
199
200 If the quoted text is not in a member function of a
201 QObject subclass, use either the tr() function of an
202 appropriate class, or the QCoreApplication::translate() function
203 directly:
204
205 \snippet doc/src/snippets/code/doc_src_i18n.qdoc 1
206
207 If you need to have translatable text completely
208 outside a function, there are two macros to help: QT_TR_NOOP()
209 and QT_TRANSLATE_NOOP(). They merely mark the text for
210 extraction by the \c lupdate utility described below.
211 The macros expand to just the text (without the context).
212
213 Example of QT_TR_NOOP():
214
215 \snippet doc/src/snippets/code/doc_src_i18n.qdoc 2
216
217 Example of QT_TRANSLATE_NOOP():
218
219 \snippet doc/src/snippets/code/doc_src_i18n.qdoc 3
220
221 If you disable the \c{const char *} to QString automatic
222 conversion by compiling your software with the macro \c
223 QT_NO_CAST_FROM_ASCII defined, you'll be very likely to catch any
224 strings you are missing. See QString::fromLatin1() for more
225 information. Disabling the conversion can make programming a bit
226 cumbersome.
227
228 If your source language uses characters outside Latin1, you
229 might find QObject::trUtf8() more convenient than
230 QObject::tr(), as tr() depends on the
231 QTextCodec::codecForTr(), which makes it more fragile than
232 QObject::trUtf8().
233
234 \section2 Use QKeySequence() for Accelerator Values
235