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 | \page linguist-manual.html
|
---|
30 | \title Qt Linguist Manual
|
---|
31 | \ingroup qttools
|
---|
32 |
|
---|
33 | \startpage {index.html}{Qt Reference Documentation}
|
---|
34 | \nextpage Qt Linguist Manual: Release Manager
|
---|
35 |
|
---|
36 | \keyword Qt Linguist
|
---|
37 |
|
---|
38 | Qt provides excellent support for translating applications into local
|
---|
39 | languages. This Guide explains how to use Qt's translation tools for
|
---|
40 | each of the roles involved in translating an application. The Guide
|
---|
41 | begins with a brief overview of the issues that must be considered,
|
---|
42 | followed by chapters devoted to each role and the supporting tools
|
---|
43 | provided.
|
---|
44 |
|
---|
45 | The \l{linguist-manager.html}{Release Manager} chapter is aimed
|
---|
46 | at the person with overall responsibility for the release of the
|
---|
47 | application. They will typically coordinate the work of the
|
---|
48 | software engineers and the translator. The chapter describes the
|
---|
49 | use of two tools. The \l{lupdate} tool is used to synchronize
|
---|
50 | source code and translations. The \l{lrelease} tool is used to
|
---|
51 | create run-time translation files for use by the released
|
---|
52 | application.
|
---|
53 |
|
---|
54 | The \l{linguist-translators.html}{Translators} chapter is for
|
---|
55 | translators. It describes the use of the \QL tool.
|
---|
56 | No computer knowledge beyond the ability to start a program and
|
---|
57 | use a text editor or word processor is required.
|
---|
58 |
|
---|
59 | The \l{linguist-programmers.html}{Programmers} chapter is for Qt
|
---|
60 | programmers. It explains how to create Qt applications that are
|
---|
61 | able to use translated text. It also provides guidance on how to
|
---|
62 | help the translator identify the context in which phrases appear.
|
---|
63 | This chapter's three short tutorials cover everything the
|
---|
64 | programmer needs to do.
|
---|
65 |
|
---|
66 | \section1 Overview of the Translation Process
|
---|
67 |
|
---|
68 | Most of the text that must be translated in an application program
|
---|
69 | consists of either single words or short phrases. These typically
|
---|
70 | appear as window titles, menu items, pop-up help text (balloon help),
|
---|
71 | and labels to buttons, check boxes and radio buttons.
|
---|
72 |
|
---|
73 | The phrases are entered into the source code by the programmer in
|
---|
74 | their native language using a simple but special syntax to identify
|
---|
75 | that the phrases require translation. The Qt tools provide context
|
---|
76 | information for each of the phrases to help the translator, and the
|
---|
77 | programmer is able to add additional context information to phrases
|
---|
78 | when necessary. The release manager generates a set of translation
|
---|
79 | files that are produced from the source files and passes these to the
|
---|
80 | translator. The translator opens the translation files using \QL,
|
---|
81 | enters their translations and saves the results back into
|
---|
82 | the translation files, which they pass back to the release manager.
|
---|
83 | The release manager then generates fast compact versions of these
|
---|
84 | translation files ready for use by the application. The tools are
|
---|
85 | designed to be used in repeated cycles as applications change and
|
---|
86 | evolve, preserving existing translations and making it easy to
|
---|
87 | identify which new translations are required. \QL also
|
---|
88 | provides a phrase book facility to help ensure consistent
|
---|
89 | translations across multiple applications and projects.
|
---|
90 |
|
---|
91 | Translators and programmers must address a number of issues because
|
---|
92 | of the subtleties and complexities of human language:
|
---|
93 |
|
---|
94 | \list
|
---|
95 |
|
---|
96 | \o A single phrase may need to be translated into several
|
---|
97 | different forms depending on context, e.g. \e open in English
|
---|
98 | might become \e{\ouml\c{}ffnen}, "open file", or \e aufbauen,
|
---|
99 | "open internet connection", in German.
|
---|
100 |
|
---|
101 | \o Keyboard accelerators may need to be changed but without
|
---|
102 | introducing conflicts, e.g. "\&Quit" in English becomes "Avslutt"
|
---|
103 | in Norwegian which doesn't contain a "Q". We cannot use a letter
|
---|
104 | that is already in use - unless we change several accelerators.
|
---|
105 |
|
---|
106 | \o Phrases that contain variables, for example, "The 25 files
|
---|
107 | selected will take 63 seconds to process", where the two numbers
|
---|
108 | are inserted programmatically at run-time may need to be reworded
|
---|
109 | because in a different language the word order and therefore the
|
---|
110 | placement of the variables may have to change.
|
---|
111 |
|
---|
112 | \endlist
|
---|
113 |
|
---|
114 | The Qt translation tools provide clear and simple solutions to these
|
---|
115 | issues.
|
---|
116 |
|
---|
117 | Chapters:
|
---|
118 |
|
---|
119 | \list
|
---|
120 | \o \l{Qt Linguist Manual: Release Manager}{Release Manager}
|
---|
121 | \o \l{Qt Linguist Manual: Translators}{Translators}
|
---|
122 | \o \l{Qt Linguist Manual: Programmers}{Programmers}
|
---|
123 | \o \l{Qt Linguist Manual: TS File Format}{TS File Format}
|
---|
124 | \endlist
|
---|
125 |
|
---|
126 | \QL and \c lupdate are able to import and export XML Localization
|
---|
127 | Interchange File Format (XLIFF) files, making it possible to take
|
---|
128 | advantage of tools and translation services that work with this
|
---|
129 | format. See the \l{Qt Linguist Manual: Translators} {Translators}
|
---|
130 | section for more information on working with these files.
|
---|
131 |
|
---|
132 | \table
|
---|
133 |
|
---|
134 | \row \o{1,2} \inlineimage wVista-Cert-border-small.png
|
---|
135 | \o \e{Qt Linguist 4.3 is Certified for Windows Vista}
|
---|
136 |
|
---|
137 | \row \o Windows Vista and the Windows Vista Start button are
|
---|
138 | trademarks or registered trademarks of Microsoft Corporation in
|
---|
139 | the United States and/or other countries.
|
---|
140 |
|
---|
141 | \endtable
|
---|
142 | */
|
---|
143 |
|
---|
144 | /*!
|
---|
145 | \page linguist-manager.html
|
---|
146 | \title Qt Linguist Manual: Release Manager
|
---|
147 |
|
---|
148 | \contentspage {Qt Linguist Manual}{Contents}
|
---|
149 | \previouspage Qt Linguist Manual
|
---|
150 | \nextpage Qt Linguist Manual: Translators
|
---|
151 |
|
---|
152 | \keyword lupdate
|
---|
153 | \keyword lrelease
|
---|
154 |
|
---|
155 | Two tools are provided for the release manager, \l lupdate and \l
|
---|
156 | lrelease. These tools can process \l qmake project files, or operate
|
---|
157 | directly on the file system.
|
---|
158 |
|
---|
159 | \section1 Qt Project Files
|
---|
160 |
|
---|
161 | The easiest method to use \l{#lupdate} {lupdate} and \l{#lrelease}
|
---|
162 | {lrelease} is by specifing a \c .pro Qt project file. There must
|
---|
163 | be an entry in the \c TRANSLATIONS section of the project file for
|
---|
164 | each language that is additional to the native language. A typical
|
---|
165 | entry looks like this:
|
---|
166 |
|
---|
167 | \snippet examples/linguist/arrowpad/arrowpad.pro 1
|
---|
168 |
|
---|
169 | Using a locale within the translation file name is useful for
|
---|
170 | determining which language to load at runtime. This is explained
|
---|
171 | in the \l{linguist-programmers.html} {Programmers} chapter.
|
---|
172 |
|
---|
173 | An example of a complete \c .pro file with four translation source
|
---|
174 | files:
|
---|
175 |
|
---|
176 | \snippet doc/src/snippets/code/doc_src_linguist-manual.qdoc 0
|
---|
177 | \snippet doc/src/snippets/code/doc_src_linguist-manual.qdoc 1
|
---|
178 |
|
---|
179 | QTextCodec::setCodecForTr() makes it possible to choose a 8-bit
|
---|
180 | encoding for literal strings that appear within \c tr() calls.
|
---|
181 | This is useful for applications whose source language is, for
|
---|
182 | example, Chinese or Japanese. If no encoding is set, \c tr() uses
|
---|
183 | Latin1.
|
---|
184 |
|
---|
185 | If you do use the QTextCodec::codecForTr() mechanism in your
|
---|
186 | application, \QL needs you to set the \c CODECFORTR
|
---|
187 | entry in the \c .pro file as well. For example:
|
---|
188 |
|
---|
189 | \snippet doc/src/snippets/code/doc_src_linguist-manual.qdoc 1
|
---|
190 |
|
---|
191 | Also, if your compiler uses a different encoding for its runtime
|
---|
192 | system as for its source code and you want to use non-ASCII
|
---|
193 | characters in string literals, you will need to set the \c
|
---|
194 | CODECFORSRC. For example:
|
---|
195 |
|
---|
196 | \snippet doc/src/snippets/code/doc_src_linguist-manual.qdoc 2
|
---|
197 |
|
---|
198 | Microsoft Visual Studio 2005 .NET appears to be the only compiler
|
---|
199 | for which this is necessary. However, if you want to write
|
---|
200 | portable code, we recommend that you avoid non-ASCII characters
|
---|
201 | in your source files. You can still specify non-ASCII characters
|
---|
202 | portably using escape sequences, for example:
|
---|
203 |
|
---|
204 | \snippet doc/src/snippets/code/doc_src_linguist-manual.qdoc 3
|
---|
205 |
|
---|
206 | \target lupdate manual
|
---|
207 | \section1 lupdate
|
---|
208 |
|
---|
209 | Usage: \c {lupdate myproject.pro}
|
---|
210 |
|
---|
211 | \l lupdate is a command line tool that finds the translatable
|
---|
212 | strings in the specified source, header and \e {Qt Designer}
|
---|
213 | interface files, and produces or updates \c .ts translation
|
---|
214 | files. The files to process and the files to update can be set at
|
---|
215 | the command line, or provided in a \c .pro file specified as an
|
---|
216 | command line argument. The produced translation files are given to
|
---|
217 | the translator who uses \QL to read the files and insert the
|
---|
218 | translations.
|
---|
219 |
|
---|
220 | Companies that have their own translators in-house may find it
|
---|
221 | useful to run \l lupdate regularly, perhaps monthly, as the
|
---|
222 | application develops. This will lead to a fairly low volume of
|
---|
223 | translation work spread evenly over the life of the project and
|
---|
224 | will allow the translators to support a number of projects
|
---|
225 | simultaneously.
|
---|
226 |
|
---|
227 | Companies that hire in translators as required may prefer to run
|
---|
228 | \l lupdate only a few times in the application's life cycle, the
|
---|
229 | first time might be just before the first test phase. This will
|
---|
230 | provide the translator with a substantial single block of work and
|
---|
231 | any bugs that the translator detects may easily be included with
|
---|
232 | those found during the initial test phase. The second and any
|
---|
233 | subsequent \l lupdate runs would probably take place during the
|
---|
234 | final beta phase.
|
---|
235 |
|
---|
236 | The TS file format is a simple human-readable XML format that
|
---|
237 | can be used with version control systems if required. \c lupdate
|
---|
238 | can also process Localization Interchange File Format (XLIFF)
|
---|
239 | format files; files in this format typically have file names that
|
---|
240 | end with the \c .xlf suffix.
|
---|
241 |
|
---|
242 | \note The minimum supported version for XLIFF format files is
|
---|
243 | 1.1. XLIFF 1.0 version files are not supported.
|
---|
244 |
|
---|
245 | Pass the \c -help option to \c lupdate to obtain the list of
|
---|
246 | supported options:
|
---|
247 |
|
---|
248 | \snippet doc/src/snippets/code/doc_src_linguist-manual.qdoc 4
|
---|
249 |
|
---|
250 | \QL is also able to import and export XLIFF files. See the
|
---|
251 | \l{Qt Linguist Manual: Translators}{Translators} section for more
|
---|
252 | information.
|
---|
253 |
|
---|
254 | \section1 lrelease
|
---|
255 |
|
---|
256 | Usage: \c {lrelease myproject.pro}
|
---|
257 |
|
---|
258 | \l lrelease is a command line tool that produces QM files out
|
---|
259 | of TS files. The QM file format is a compact binary format
|
---|
260 | that is used by the localized application. It provides extremely
|
---|
261 | fast lookups for translations. The TS files \l lrelease
|
---|
262 | processes can be specified at the command line, or given
|
---|
263 | indirectly by a Qt \c .pro project file.
|
---|
264 |
|
---|
265 | This tool is run whenever a release of the application is to be
|
---|
266 | made, from initial test version through to final release
|
---|
267 | version. If the QM files are not created, e.g. because an
|
---|
268 | alpha release is required before any translation has been
|
---|
269 | undertaken, the application will run perfectly well using the text
|
---|
270 | the programmers placed in the source files. Once the QM files
|
---|
271 | are available the application will detect them and use them
|
---|
272 | automatically.
|
---|
273 |
|
---|
274 | Note that lrelease will only incorporate translations that are
|
---|
275 | marked as "finished". Otherwise the original text will be used
|
---|
276 | instead.
|
---|
277 |
|
---|
278 | Pass the \c -help option to \c lrelease to obtain the list of
|
---|
279 | supported options:
|
---|
280 |
|
---|
281 | \snippet doc/src/snippets/code/doc_src_linguist-manual.qdoc 5
|
---|
282 |
|
---|
283 | \section1 Missing Translations
|
---|
284 |
|
---|
285 | Both \l lupdate and \l lrelease may be used with TS
|
---|
286 | translation source files which are incomplete. Missing
|
---|
287 | translations will be replaced with the native language phrases at
|
---|
288 | runtime.
|
---|
289 | */
|
---|
290 |
|
---|
291 | /*!
|
---|
292 | \page linguist-translators.html
|
---|
293 | \title Qt Linguist Manual: Translators
|
---|
294 |
|
---|
295 | \contentspage {Qt Linguist Manual}{Contents}
|
---|
296 | \previouspage Qt Linguist Manual: Release Manager
|
---|
297 | \nextpage Qt Linguist Manual: Programmers
|
---|
298 |
|
---|
299 | Contents
|
---|
300 |
|
---|
301 | \tableofcontents
|
---|
302 |
|
---|
303 | \section1 The One Minute Guide to Using Qt Linguist
|
---|
304 |
|
---|
305 | \QL is a tool for adding translations to Qt applications. Run \QL
|
---|
306 | from the taskbar menu, or by double clicking the desktop icon, or
|
---|
307 | by entering the command \c {linguist} at the command line. Once
|
---|
308 | \QL has started, choose \menu{File|Open} from the \l{menubar}
|
---|
309 | {menu bar} and select a translation source (TS file) to
|
---|
310 | load. If you do not have a TS file, see the \l {Qt Linguist
|
---|
311 | Manual: Release Manager} {release manager manual} to learn how to
|
---|
312 | generate one.
|
---|
313 |
|
---|
314 | The \QL main window is divided into several, dockable subwindows
|
---|
315 | arranged around a central \l{The Translation Area} {translation
|
---|
316 | area}. The \l{Context Window} {context list} is normally shown
|
---|
317 | on the left, and the \l{Sources and Forms Window} {source code},
|
---|
318 | \l{Strings Window} {string list}, and either the \l{Phrases and
|
---|
319 | Guesses Window} {phrases and guesses}, or the \l{Warnings Window}
|
---|
320 | {warnings} are shown above and below the \l{The Translation Area}
|
---|
321 | {translations area}.
|
---|
322 |
|
---|
323 | With a translation file loaded, select a context from the
|
---|
324 | \l{Context Window} {context list} on the left. Selecting a context
|
---|
325 | loads the translatable strings found in that context into the
|
---|
326 | \l{Strings Window} {string list}. Selecting one of the strings
|
---|
327 | copies that string as the \key{Source text} in the \l{The
|
---|
328 | Translation Area} {translation area}. Click in the text entry
|
---|
329 | widget below the copied string and type your translation for that
|
---|
330 | string. To accept the translation, either press the green
|
---|
331 | \key{tick mark} button on the toolbar, or click the icon to the
|
---|
332 | left of the selected source string in the string list. Repeat this
|
---|
333 | process until all strings in the string list are marked with
|
---|
334 | \inlineimage linguist-check-on.png
|
---|
335 | or
|
---|
336 | \inlineimage linguist-check-warning.png
|
---|
337 | . Then select the next context and continue.
|
---|
338 |
|
---|
339 | Translation options are shown in the \l{Phrases and Guesses
|
---|
340 | Window} {phrases and guesses window}. If the phrases and guesses
|
---|
341 | window is not visible, click the \key{Phrases and guesses} tab at
|
---|
342 | the bottom of the main window. The phrases and guesses window
|
---|
343 | shows possible translations for the current string. These
|
---|
344 | translation "guesses" have been read from phrase books
|
---|
345 | (\menu{Phrases|Open Phrase Book...}). The current string's
|
---|
346 | current translation is also shown here. To select a guess, double
|
---|
347 | click it in the phrases and guesses window or use the keyboard
|
---|
348 | shortcut shown to the right of the guess.
|
---|
349 |
|
---|
350 | \QL can automatically check whether your translation strings pass
|
---|
351 | a list of \l{Validation Tests} {validation tests}. Validation test
|
---|
352 | failures are shown in the \l{Warnings Window} {warnings window}.
|
---|
353 | If the warnings window is not visible, click the \key{Warnings}
|
---|
354 | tab at the bottom of the main window.
|
---|
355 |
|
---|
356 | Finally, if the source code for the contexts is accessible, the
|
---|
357 | \l{Sources and Forms Window} {source code window} shows the
|
---|
358 | context where the current string is used. If the source code
|
---|
359 | window is not visible, click the \key{Sources and Forms} tab at
|
---|
360 | the bottom of the main window.
|
---|
361 |
|
---|
362 | At the end of the session choose \menu{File|Save} from the menu
|
---|
363 | bar and then \menu{File|Exit} to quit.
|
---|
364 |
|
---|
365 | \section1 The Qt Linguist Window
|
---|
366 |
|
---|
367 | \image linguist-linguist.png "Linguist UI Snapshot"
|
---|
368 |
|
---|
369 | This \QL main window is divided into dockable subwindows arranged
|
---|
370 | around a central \l{The Translation Area} {translation area}. The
|
---|
371 | subwindows are: \l{Context Window} {Context}, \l{Sources and Forms
|
---|
372 | Window} {Sources and Forms}, \l{Strings Window} {Strings},
|
---|
373 | \l{Phrases and Guesses Window} {Phrases and guesses}, and
|
---|
374 | \l{Warnings Window} {Warnings} (hidden in the UI snapsot). The
|
---|
375 | translation area is always visible, but the dockable subwindows
|
---|
376 | can be activated or deactivated in the \menu{View|Views} menu, and
|
---|
377 | dragged around by their title bars and dropped in the translation
|
---|
378 | area or even outside the main window.
|
---|
379 |
|
---|
380 | \section2 Context Window
|
---|
381 |
|
---|
382 | The context window normally appears on the left side of the main
|
---|
383 | window. It lists the contexts in which strings to be translated
|
---|
384 | appear. The column labeled \e{Context} lists the context names in
|
---|
385 | alphabetical order. Each context is the name of a subclass of
|
---|
386 | QObject. There can also be a context for QObject itself, which
|
---|
387 | contains strings passed to the static function QObject::tr().
|
---|
388 | There can also be an \e{<unnamed context>}, which contains strings
|
---|
389 | that aren't in a subclass of QObject.
|
---|
390 |
|
---|
391 | To the left of the \e{Context} column is a column labeled
|
---|
392 | \inlineimage linguist-check-obsolete.png
|
---|
393 | . This column uses the following list of icons to summarize the
|
---|
394 | current translation state for each context:
|
---|
395 |
|
---|
396 | \list
|
---|
397 |
|
---|
398 | \o \inlineimage linguist-check-on.png
|
---|
399 | All strings in the context have been translated, and all the
|
---|
400 | translations passed the \l{Validation Tests} {validation tests}.
|
---|
401 |
|
---|
402 | \o \inlineimage linguist-check-warning.png
|
---|
403 | All strings in the context have been translated or marked as
|
---|
404 | translated, but at least one translation failed the \l{Validation
|
---|
405 | Tests} {validation tests}.
|
---|
406 |
|
---|
407 | \o \inlineimage linguist-check-off.png
|
---|
408 | At least one string in the context has not been translated or is
|
---|
409 | not marked as translated.
|
---|
410 |
|
---|
411 | \o \inlineimage linguist-check-obsolete.png
|
---|
412 | None of the translated strings still appears in the context. This
|
---|
413 | usually means the context itself no longer exists in the
|
---|
414 | application.
|
---|
415 |
|
---|
416 | \endlist
|
---|
417 |
|
---|
418 | To the right of the \e{Context} column is the \e{Items} column.
|
---|
419 | Each entry in the \e{Items} column is a pair of numbers separated
|
---|
420 | by a slash ("/"). The number to the right of the slash is the
|
---|
421 | number of translatable strings in the context. The number to the
|
---|
422 | left of the slash is the number of those strings that currently
|
---|
423 | have translations. i.e., if the numbers are equal, all the
|
---|
424 | translatable strings in the context have translations.
|
---|
425 |
|
---|
426 | In the UI snapshot above, the \bold{MessageEditor} context is
|
---|
427 | selected. Its \e{Items} entry shows \bold{18/18}, which means it
|
---|
428 | has 18 translatable strings and all 18 strings currently have
|
---|
429 | translations. However, the context has been marked with the
|
---|
430 | \inlineimage linguist-check-warning.png
|
---|
431 | icon, which means that at least one of the current translations
|
---|
432 | failed a \l{Validation Tests} {validation test}. In the
|
---|
433 | \l{Strings Window} {strings window} to the right, we see that one
|
---|
434 | of the strings is indeed marked with the
|
---|
435 | \inlineimage linguist-check-warning.png
|
---|
436 | icon.
|
---|
437 |
|
---|
438 | The context window is a dockable window. It can be dragged to
|
---|
439 | another position in the main window, or dragged out of the main
|
---|
440 | window to be a separate window. If you move the context window,
|
---|
441 | \QL remembers the new position and puts the context window there
|
---|
442 | whenever you start the program. If the context window has been
|
---|
443 | closed, it can be restored by pressing \key{F6}.
|
---|
444 |
|
---|
445 | \section2 Strings Window
|
---|
446 |
|
---|
447 | The strings window normally appears on the right in the main
|
---|
448 | window, above the \l{The Translation Area} {translation area}. Its
|
---|
449 | \e{Source text} column lists all the translatable strings found in
|
---|
450 | the current context. Selecting a string makes that string the
|
---|
451 | current string in the \l{The Translation Area} {translation area}.
|
---|
452 |
|
---|
453 | To the left of the \e{Source text} column is a column labeled
|
---|
454 | \inlineimage linguist-check-obsolete.png
|
---|
455 | . This column is similar to the one in the \l{Context Window}
|
---|
456 | {context window}, but here you can click on the icon to change the
|
---|
457 | translation acceptance state for each string in the list. A tick
|
---|
458 | mark, green or yellow, means the string has been translated and
|
---|
459 | the user has accepted the translation. A question mark means
|
---|
460 | either that the user has not accepted the string's translation or
|
---|
461 | that the string doesn't have a translation. The table below
|
---|
462 | explains the acceptance states and their icons:
|
---|
463 |
|
---|
464 | \target String Translation States
|
---|
465 |
|
---|
466 | \table
|
---|
467 | \header
|
---|
468 | \o State
|
---|
469 | \o Icon
|
---|
470 | \o Description
|
---|
471 |
|
---|
472 | \row
|
---|
473 | \o Accepted/Correct
|
---|
474 | \o \inlineimage linguist-check-on.png
|
---|
475 | \o The source string has a translation (possibly empty); the user
|
---|
476 | has accepted the translation, and the translation passes all the
|
---|
477 | \l{Validation Tests} {validation tests}. If the translation is
|
---|
478 | empty, the user has chosen to leave it empty. Click the icon to
|
---|
479 | revoke acceptance of the translation and decrement the number of
|
---|
480 | accepted translations in the \e{Items} column of the \l{Context
|
---|
481 | Window} {context list} by 1. The state is reset to
|
---|
482 | \inlineimage linguist-check-off.png
|
---|
483 | if the string has a translation, or to
|
---|
484 | \inlineimage linguist-check-empty.png
|
---|
485 | if the string's translation is empty. If \c{lupdate} changes the
|
---|
486 | contents of a string, its acceptance state is automatically reset
|
---|
487 | to \inlineimage linguist-check-off.png
|
---|
488 | .
|
---|
489 |
|
---|
490 | \row
|
---|
491 | \o Accepted/Warnings
|
---|
492 | \o \inlineimage linguist-check-warning.png
|
---|
493 | \o The user has accepted the translation, but the translation does
|
---|
494 | not pass all the \l{Validation Tests} {validation tests}. The
|
---|
495 | validation test failures are shown in the \l{Warnings Window}
|
---|
496 | {warnings window}. Click the icon to revoke acceptance of the
|
---|
497 | translation. The state is reset to \inlineimage linguist-danger.png
|
---|
498 | , and the number of accepted translations in the \e{Items} column
|
---|
499 | of the \l{Context Window} {context list} is decremented by 1.
|
---|
500 |
|
---|
501 | \row
|
---|
502 | \o Not Accepted
|
---|
503 | \o \inlineimage linguist-check-off.png
|
---|
504 | \o The string has a non-empty translation that passes all the
|
---|
505 | \l{Validation Tests} {validation tests}, but the user has not yet
|
---|
506 | accepted the translation. Click the icon or press \key{Ctrl+Enter}
|
---|
507 | to accept the translation. The state is reset to
|
---|
508 | \inlineimage linguist-check-on.png
|
---|
509 | , and the number of accepted translations in the \e{Items} column
|
---|
510 | of the \l{Context Window} {context list} is incremented by 1.
|
---|
511 |
|
---|
512 | \row
|
---|
513 | \o No Translation
|
---|
514 | \o \inlineimage linguist-check-empty.png
|
---|
515 | \o The string does not have a translation. Click the icon to
|
---|
516 | accpet the empty translation anyway. The state is reset to
|
---|
517 | \inlineimage linguist-check-on.png
|
---|
518 | , and the number of accepted translations in the \e{Items} column
|
---|
519 | of the \l{Context Window} {context list} is incremented by 1.
|
---|
520 |
|
---|
521 | \row
|
---|
522 | \o Validation Failures
|
---|
523 | \o \inlineimage linguist-danger.png
|
---|
524 | \o The string has a translation, but the translation does not
|
---|
525 | pass all the \l{Validation Tests} {validation tests}. Validation
|
---|
526 | test failures are shown in the \l{Warnings Window} {warnings}
|
---|
527 | window. Click on the icon or press \key{Ctrl+Return} to accept
|
---|
528 | the translation even with validation failures. The state is
|
---|
529 | reset to \inlineimage linguist-check-warning.png
|
---|
530 | . We recommended editing the translation to fix the causes of
|
---|
531 | the validation failures. The state will reset automatically to
|
---|
532 | \inlineimage linguist-check-off.png
|
---|
533 | , when all the failures have been fixed.
|
---|
534 |
|
---|
535 | \row
|
---|
536 | \o Obsolete
|
---|
537 | \o \inlineimage linguist-check-obsolete.png
|
---|
538 | \o The string is obsolete. It is no longer used in the context.
|
---|
539 | See the \l{Qt Linguist Manual: Release Manager} {Release Manager}
|
---|
540 | for instructions on how to remove obsolete messages from the file.
|
---|
541 |
|
---|
542 | \endtable
|
---|
543 |
|
---|
544 | The string list is a dockable subwindow. If it has been closed,
|
---|
545 | restored it by pressing \key{F7}.
|
---|
546 |
|
---|
547 | \section2 The Translation Area
|
---|
548 |
|
---|
549 | The translation area is in the middle of the main window, to the
|
---|
550 | right of the \l{Context Window} {context list}. It doesn't have a
|
---|
551 | title bar, so you can't drag it around. Instead, you drag and drop
|
---|
552 | the other subwindows to arrange them around the translation area.
|
---|
553 | The string currently selected in the \l{Strings Window} {string
|
---|
554 | list} appears at the top of the translation area, under the label
|
---|
555 | \menu{Source text}. Note that all blanks in the source text have
|
---|
556 | been replaced by "." so the translator can see the spacing
|
---|
557 | required within the text.
|
---|
558 |
|
---|
559 | If the developer provides a \l{QObject::tr()} {disambiguating
|
---|
560 | comment}, it will appear below the source text area, under the
|
---|
561 | label \menu{Developer comments}.
|
---|
562 |
|
---|
563 | Below the source text and optional developer comments are two text
|
---|
564 | entry widgets for the translator, one for entering the translation
|
---|
565 | of the current string, and one for the translator to enter an
|
---|
566 | optional comment to be read by other translators.
|
---|
567 |
|
---|
568 | When \l{Translating Multiple Languages Simultaneously} {multiple
|
---|
569 | languages} are being translated, this sequence of fields is
|
---|
570 | repeated for each language. See aso \l {Changing the Target
|
---|
571 | Locale}.
|
---|
572 |
|
---|
573 | \section2 Phrases and Guesses Window
|
---|
574 |
|
---|
575 | If the current string in the \l{Strings Window} {string list}
|
---|
576 | appears in one or more of the \l{Phrase Books} {phrase books}
|
---|
577 | that have been loaded, the current string and its phrase book
|
---|
578 | translation(s) will be listed in this window. If the current
|
---|
579 | string is the same as, or similar to, another string that has
|
---|
580 | already been translated, that other string and its translation
|
---|
581 | will also be listed in this window.
|
---|
582 |
|
---|
583 | To use a translation from the Phrases and Guesses Window, you can
|
---|
584 | double click the translation, and it will be copied into the
|
---|
585 | translation area, or you can use the translation's \e{Guess}
|
---|
586 | hotkey on the right. You can also press \key{F10} to move the
|
---|
587 | focus to the Phrases and Guesses Window, then use the up and down
|
---|
588 | arrow keys to find the desired translation, and and then press
|
---|
589 | \key{Enter} to copy it to the translation area. If you decide
|
---|
590 | that you don't want to copy a phrase after all, press \key{Esc} to
|
---|
591 | return the focus to the translation area.
|
---|
592 |
|
---|
593 | The Phrases and Guesses Window is a dockable window. If it has
|
---|
594 | been closed, it can be made visible by pressing the \e{Phrases and
|
---|
595 | guesses} tab at the bottom of the window, or by pressing
|
---|
596 | \key{F10}.
|
---|
597 |
|
---|
598 | \section2 Sources and Forms Window
|
---|
599 |
|
---|
600 | If the source files containing the translatable strings are
|
---|
601 | available to \QL, this window shows the source context of the
|
---|
602 | current string in the \l{Strings Window} {string list}. The source
|
---|
603 | code line containing the current string should be shown and
|
---|
604 | highlighted. If the file containing the source string is not
|
---|
605 | found, the expected absolute file path is shown.
|
---|
606 |
|
---|
607 | If the source context shows the wrong source line, it probably
|
---|
608 | means the translation file is out of sync with the source files.
|
---|
609 | To re-sync the translation file with the source files, see the
|
---|
610 | \l{lupdate manual} {lupdate manual}.
|
---|
611 |
|
---|
612 | The Sources and Forms window is a dockable window. If it has been
|
---|
613 | closed, it can be made visible again by pressing the \e{Sources
|
---|
614 | and Forms} tab at the bottom of the window, or by pressing
|
---|
615 | \key{F9}.
|
---|
616 |
|
---|
617 | \section2 Warnings Window
|
---|
618 |
|
---|
619 | If the translation you enter for the current string fails any of
|
---|
620 | the active \l{Validation Tests} {validation tests}, the failures
|
---|
621 | are listed in the warnings window. The first of these failure
|
---|
622 | messages is also shown in the status bar at the bottom of the main
|
---|
623 | window. Note that only \e{active} validation tests are
|
---|
624 | reported. To see which validation tests are currently active, or
|
---|
625 | to activate or deactivate tests, use the \menu{Validation} menu
|
---|
626 | from the \l{menubar}{menu bar}.
|
---|
627 |
|
---|
628 | The Warnings window is a dockable window. If it has been closed,
|
---|
629 | it can be made visible by pressing the \e{Warnings} tab at the
|
---|
630 | bottom of the window, or by pressing \key{F8}.
|
---|
631 |
|
---|
632 | \target multiple languages
|
---|
633 | \section2 Translating Multiple Languages Simultaneously
|
---|
634 |
|
---|
635 | Qt Linguist can now load and edit multiple translation files
|
---|
636 | simultaneously. One use for this is the case where you know two
|
---|
637 | languages better than you know English (Polish and Japanese, say),
|
---|
638 | and you are given an application's Polish translation file and
|
---|
639 | asked to update the application's Japanese translation file. You
|
---|
640 | are more comfortable translating Polish to Japanese than you are
|
---|
641 | translating English to Japanese.
|
---|
642 |
|
---|
643 | Below is the UI snapshot shown earlier, but this time with both
|
---|
644 | \e{Polish} and \e{Japanese} translation files loaded.
|
---|
645 |
|
---|
646 | \image linguist-linguist_2.png
|
---|
647 |
|
---|
648 | The first thing to notice is that the \l{The Translation Area}
|
---|
649 | {translation area} has text editing areas for both Polish and
|
---|
650 | Japanese, and these are color-coded for easier separation.
|
---|
651 | Second, the \l{Context Window} and the \l{Strings Window} both
|
---|
652 | have two clomuns labeled \inlineimage linguist-check-obsolete.png
|
---|
653 | instead of one, and although it may be hard to tell, these columns
|
---|
654 | are also color-coded with the same colors. The left-most column in
|
---|
655 | either case applies to the top-most language area (Polish above)
|
---|
656 | in the \l{The Translation Area} {translation area}, and the
|
---|
657 | right-most column applies to the bottom language area.
|
---|
658 |
|
---|
659 | The \e{Items} column in the \l{Context Window} combines the values
|
---|
660 | for both languages. The best way to see this is to look at the
|
---|
661 | value for the \bold{MessageEditor} context, which is the one
|
---|
662 | selected in the snapshot shown above. Recall that in the first UI
|
---|
663 | snapshot (Polish only), the numbers for this context were
|
---|
664 | \e{18/18}, meaning 18 translatable strings had been found in the
|
---|
665 | context, and all 18 strings had accepted translations. In the UI
|
---|
666 | snapshot above, the numbers for the \bold{MessageEditor} context
|
---|
667 | are now \e{1/18}, meaning that both languages have 18 translatable
|
---|
668 | strings for that context, but for Japanese, only 1 of the 18
|
---|
669 | strings has an accepted translation. The
|
---|
670 | \inlineimage linguist-check-off.png
|
---|
671 | icon in the Japanese column means that at least one string in the
|
---|
672 | context doesn't have an accepted Japanese translation yet. In fact,
|
---|
673 | 17 of the 18 strings don't have accepted Japanese translations yet.
|
---|
674 | We will see \e{18/18} in the \e{Items} column when all 18 strings
|
---|
675 | have accepted translations for all the loaded translation files,
|
---|
676 | e.g., both Polish and Japanese in the snapshot.
|
---|
677 |
|
---|
678 | \section1 Common Tasks
|
---|
679 |
|
---|
680 | \section2 Leaving a Translation for Later
|
---|
681 |
|
---|
682 | If you wish to leave a translation press \key{Ctrl+L} (Next
|
---|
683 | Unfinished) to move to the next unfinished translation. To move to
|
---|
684 | the next translation (whether finished or unfinished) press
|
---|
685 | \key{Shift+Ctrl+L}. You can also navigate using the Translation
|
---|
686 | menu. If you want to go to a different context entirely, click the
|
---|
687 | context you want to work on in the Context list, then click the
|
---|
688 | source text in the \l{Strings Window} {string list}.
|
---|
689 |
|
---|
690 | \section2 Phrases That Require Multiple Translations Depending on Context
|
---|
691 |
|
---|
692 | The same phrase may occur in two or more contexts without conflict. Once
|
---|
693 | a phrase has been translated in one context, \QL notes
|
---|
694 | that the translation has been made and when the translator reaches a
|
---|
695 | later occurrence of the same phrase \QL will provide
|
---|
696 | the previous translation as a possible translation candidate in the
|
---|
697 | \l{Phrases and Guesses Window}.
|
---|
698 |
|
---|
699 | If a phrase occurs more than once in a particular context it will
|
---|
700 | only be shown once in \QL's \l{Context Window} {context list} and
|
---|
701 | the translation will be applied to every occurrence within the
|
---|
702 | context. If the same phrase needs to be translated differently
|
---|
703 | within the same context the programmer must provide a
|
---|
704 | distinguishing comment for each of the phrases concerned. If such
|
---|
705 | comments are used the duplicate phrases will appear in the
|
---|
706 | \l{Context Window} {context list}. The programmers comments will
|
---|
707 | appear in the \l{The Translation Area} {translation area} on a
|
---|
708 | light blue background.
|
---|
709 |
|
---|
710 | \section2 Changing Keyboard Accelerators
|
---|
711 |
|
---|
712 | A keyboard accelerator is a key combination that, when pressed,
|
---|
713 | causes an application to perform an action. There are two kinds of
|
---|
714 | keyboard accelerators: Alt key and Ctrl key accelerators.
|
---|
715 |
|
---|
716 | \section3 Alt Key Accelerators
|
---|
717 |
|
---|
718 | Alt key accelerators are used in menu selection and on buttons.
|
---|
719 | The underlined character in a menu item or button label signifies
|
---|
720 | that pressing the Alt key with the underlined character will
|
---|
721 | perform the same action as clicking the menu item or pressing the
|
---|
722 | button. For example, most applications have a \e{File} menu with
|
---|
723 | the "F" in the word "File" underlined. In these applications the
|
---|
724 | \e{File} menu can be invoked either by clicking the word "File" on
|
---|
725 | the menu bar or by pressing \e{Alt+F}. To identify an accelerator
|
---|
726 | key in the translation text ("File") precede it with an ampersand,
|
---|
727 | e.g. \e{\&File}. If a string to be translated has an ampersand in
|
---|
728 | it, then the translation for that string should also have an
|
---|
729 | ampersand in it, preferably in front of the same character.
|
---|
730 |
|
---|
731 | The meaning of an Alt key accelerator can be determined from the
|
---|
732 | phrase in which the ampersand is embedded. The translator can
|
---|
733 | change the character part of the Alt key accelerator, if the
|
---|
734 | translated phrase does not contain the same character or if that
|
---|
735 | character has already been used in the translation of some other
|
---|
736 | Alt key accelerator. Conflicts with other Alt key accelerators
|
---|
737 | must be avoided within a context. Note that some Alt key
|
---|
738 | accelerators, usually those on the menu bar, may apply in other
|
---|
739 | contexts.
|
---|
740 |
|
---|
741 | \section3 Ctrl Key Accelerators
|
---|
742 |
|
---|
743 | Ctrl key accelerators can exist independently of any visual
|
---|
744 | control. They are often used to invoke actions in menus that would
|
---|
745 | otherwise require multiple keystrokes or mouse clicks. They may
|
---|
746 | also be used to perform actions that do not appear in any menu or
|
---|
747 | on any button. For example, most applications that have a \e{File}
|
---|
748 | menu have a \e{New} submenu item in the \e{File} menu. The \e{New}
|
---|
749 | item might appear as "\underline{N}ew Ctrl+N" in the \e{File}
|
---|
750 | menu, meaning the \e{New} menu can be invoked by simply pressing
|
---|
751 | \key{Ctrl+N}, instead of either clicking \e{File} with the mouse
|
---|
752 | and then clicking \e{New} with the mouse, or by entering \e{Alt+F}
|
---|
753 | and \e{N}.
|
---|
754 |
|
---|
755 | Each Ctrl key accelerator is shown in the \l{Strings Window}
|
---|
756 | {string list} as a separate string, e.g. \key{Ctrl+Enter}. Since
|
---|
757 | the string doesn't have a context to give it meaning, e.g. like
|
---|
758 | the context of the phrase in which an Alt key accelerator appears,
|
---|
759 | the translator must rely on the UI developer to include a
|
---|
760 | \l{QObject::tr()} {disambiguation comment} to explain the action
|
---|
761 | the Ctrl key accelerator is meant to perform. This disambiguating
|
---|
762 | comment (if provided by the developer) will appear under
|
---|
763 | \e{Developer comments} in the \l{The Translation Area}
|
---|
764 | {translation area} under the \e{Source text} area.
|
---|
765 |
|
---|
766 | Ideally Ctrl key accelerators are translated simply by copying
|
---|
767 | them directly using \e {Copy from source text} in the
|
---|
768 | \menu{Translation} menu. However, in some cases the character will
|
---|
769 | not make sense in the target language, and it must be
|
---|
770 | changed. Whichever character (alpha or digit) is chosen, the
|
---|
771 | translation must be in the form "Ctrl+" followed by the upper case
|
---|
772 | character. \e{Qt} will automatically display the correct name at
|
---|
773 | run-time. As with Alt key accelerators, if the translator changes
|
---|
774 | the character, the new character must not conflict with any other
|
---|
775 | Ctrl key accelerator.
|
---|
776 |
|
---|
777 | \warning Do not translate the "Alt", "Ctrl" or "Shift" parts of
|
---|
778 | the accelerators. \e{Qt} relies on these strings being there. For
|
---|
779 | supported languages, \e {Qt} automatically translates these
|
---|
780 | strings.
|
---|
781 |
|
---|
782 | \section2 Handling Numbered Arguments and Plurals
|
---|
783 |
|
---|
784 | Some phrases contain numbered arguments. A numbered argument is a
|
---|
785 | placeholder that will be replaced with text at run-time. A numbered
|
---|
786 | argument appears in a source string as a percent sign followed by
|
---|
787 | a digit. Consider an example: \c{After processing file %1, file %2
|
---|
788 | is next in line}. In this string to be translated, \c{%1} and
|
---|
789 | \c{%2} are numbered arguments. At run-time, \c{%1} and \c{%2} will
|
---|
790 | be replaced with the first and next file names respectively. The
|
---|
791 | same numbered arguments must appear in the translation, but not
|
---|
792 | necessarily in the same order. A German translation of the string
|
---|
793 | might reverse the phrases, e.g. \c{Datei %2 wird bearbeitet, wenn
|
---|
794 | Datei %1 fertig ist}. Both numbered arguments appear in the
|
---|
795 | translation, but in the reverse order. \c{%i} will always be
|
---|
796 | replaced by the same text in the translation stringss, regardless
|
---|
797 | of where argument \e{i} appears in the argument sequence in the
|
---|
798 | source string.
|
---|
799 |
|
---|
800 | The use of numbered arguments is often accompanied by the use of
|
---|
801 | plurals in the source text. In many languages, the form of the
|
---|
802 | text will depend on the value shown, and more than one translation
|
---|
803 | is required. If the developers have marked up the source text in
|
---|
804 | correct way, fields for each of the possible plural forms will be
|
---|
805 | available in the translation area. (The
|
---|
806 | \l{Writing Source Code for Translation#Handling Plurals}{Writing Source Code for Translation}
|
---|
807 | document contains details about this feature for developers.)
|
---|
808 |
|
---|
809 | \section2 Reusing Translations
|
---|
810 |
|
---|
811 | If the translated text is similar to the source text, choose the
|
---|
812 | \e {Copy from source text} entry in the \menu Translation menu (press
|
---|
813 | \key{Ctrl+B}) which will copy the source text into the
|
---|
814 | \l{The Translation Area} {translation area}.
|
---|
815 |
|
---|
816 | \QL automatically lists possible translations from any open
|
---|
817 | \l{Phrase Books} {phrase books} in the \l{Phrases and Guesses
|
---|
818 | Window}, as well as similar or identical phrases that have already
|
---|
819 | been translated.
|
---|
820 |
|
---|
821 | \section2 Changing the Target Locale
|
---|
822 |
|
---|
823 | \QL displays the target language in the \l{The Translation Area}
|
---|
824 | {translation area}, and adapts the number of input fields for
|
---|
825 | plural forms accordingly. If not explicitly set, \QL guesses the
|
---|
826 | target language and country by evaluating the translation source
|
---|
827 | file name. For example, \c app_de.ts sets the target language to German,
|
---|
828 | and \c app_de_ch.ts sets the target language to German and the
|
---|
829 | target country to Switzerland (this also helps loading
|
---|
830 | translations for the current locale automatically; see
|
---|
831 | \l{linguist-programmers.html}{Programmers Manual} for details).
|
---|
832 | If your files do not follow this convention, you can also set the
|
---|
833 | locale information explicitly using \e {Translation File Settings}
|
---|
834 | in the \menu Edit menu.
|
---|
835 |
|
---|
836 | \image linguist-translationfilesettings.png
|
---|
837 |
|
---|
838 | \section1 Phrase Books
|
---|
839 |
|
---|
840 | A \QL phrase book is a set of source phrases, target
|
---|
841 | (translated) phrases, and optional definitions. Typically one phrase book
|
---|
842 | will be created per language and family of applications. Phrase books
|
---|
843 | are used to provide a common set of translations to help ensure consistency.
|
---|
844 | They can also be used to avoid duplication of effort since the translations
|
---|
845 | for a family of applications can be produced once in the phrase book.
|
---|
846 | If the translator reaches an untranslated phrase that is the same as a
|
---|
847 | source phrase in a phrase book, \QL will show the
|
---|
848 | phrase book entry in the \l {Phrases and Guesses Window}.
|
---|
849 |
|
---|
850 | \section2 Creating and Editing Phrase Books
|
---|
851 |
|
---|
852 | \image linguist-phrasebookdialog.png
|
---|
853 |
|
---|
854 | Before a phrase book can be edited it must be created or, if it already
|
---|
855 | exists, opened. Create a new phrase book by selecting
|
---|
856 | \menu{Phrase|New Phrase Book} from the menu bar. You must enter a
|
---|
857 | filename and may change the location of the file if you wish. A newly
|
---|
858 | created phrase book is automatically opened. Open an existing phrase
|
---|
859 | book by choosing \menu{Phrase|Open Phrase Book} from the menu bar.
|
---|
860 |
|
---|
861 | The phrase book contents can be displayed and changed by selecting
|
---|
862 | \menu{Phrase|Edit Phrase Book}, and then activating the phrase book you
|
---|
863 | want to work on. This will pop up the Phrase Book Dialog as shown
|
---|
864 | in the image above. To add a new phrase click the \gui{New Phrase}
|
---|
865 | button (or press Alt+N) and type in a new source phrase. Press Tab and
|
---|
866 | type in the translation. Optionally press Tab and enter a definition --
|
---|
867 | this is useful to distinguish different translations of the same source
|
---|
868 | phrase. This process may be repeated as often as necessary. You can delete
|
---|
869 | a phrase by selecting it in the phrases list and clicking
|
---|
870 | Remove Phrase. Click the \gui Close button (press Esc) once you've finished
|
---|
871 | adding (and removing) phrases.
|
---|
872 |
|
---|
873 | \section2 Shortcuts for Editing Phrase Books
|
---|
874 |
|
---|
875 | You can also create a new phrase book entry directly out of the translation you
|
---|
876 | are working on: Clicking \menu{Phrases|Add to Phrase Book} or pressing
|
---|
877 | \key{Ctrl+T} will add the source text and the content of the first translation
|
---|
878 | field to the current phrase book. If multiple phrase books are loaded,
|
---|
879 | you have to specify the phrase book to add the entry to in a dialogue.
|
---|
880 | If you detect an error in a phrase book entry that is shown in the
|
---|
881 | \l{Phrases and Guesses Window}, you can also edit it in place by right
|
---|
882 | clicking on the entry, and selecting \menu{Edit}. After fixing the error
|
---|
883 | press \key{Return} to leave the editing mode.
|
---|
884 |
|
---|
885 | \section2 Batch Translation
|
---|
886 |
|
---|
887 | \image linguist-batchtranslation.png
|
---|
888 |
|
---|
889 | Use the batch translation feature of \QL to automatically
|
---|
890 | translate source texts that are also in a phrase book. Selecting
|
---|
891 | \menu{Tools|Batch Translation} will show you the batch translation dialog,
|
---|
892 | which let you configure which phrase books to use in what order during the
|
---|
893 | batch translation process. Furthermore you can set whether only entries
|
---|
894 | with no present translation should be considered, and whether batch translated
|
---|
895 | entries should be set to finished (see also \l {String Translation States}).
|
---|
896 |
|
---|
897 | \section1 Validation Tests
|
---|
898 |
|
---|
899 | \QL provides four kinds of validation tests for translations.
|
---|
900 |
|
---|
901 | \list 1
|
---|
902 | \o \e {Accelerator validation} detects translated phrases
|
---|
903 | that do not have an ampersand when the source phrase does and vice
|
---|
904 | versa.
|
---|
905 | \o \e {Punctuation validation} detects differences in the
|
---|
906 | terminating punctuation between source and translated phrases when this
|
---|
907 | may be significant, e.g. warns if the source phrase ends with an
|
---|
908 | ellipsis, exclamation mark or question mark, and the translated phrase
|
---|
909 | doesn't and vice versa.
|
---|
910 | \o \e {Phrases validation} detects source phrases that are
|
---|
911 | also in the phrase book but whose translation differs from that given in
|
---|
912 | the phrase book.
|
---|
913 | \o \e {Place marker validation} detects whether the same variables
|
---|
914 | (like \c %1, \c %2) are used both in the source text and in the translation.
|
---|
915 | \endlist
|
---|
916 |
|
---|
917 | Validation may be switched on or off from the menu bar's
|
---|
918 | Validation item or using the toolbar buttons. Unfinished phrases
|
---|
919 | that fail validation are marked with an exclamation mark in the
|
---|
920 | source text pane. Finished phrases will get a yellow tick
|
---|
921 | instead. If you switch validation off and then switch it on later,
|
---|
922 | \QL will recheck all phrases and mark any that fail
|
---|
923 | validation. See also \l{String Translation States}.
|
---|
924 |
|
---|
925 | \section1 Form Preview
|
---|
926 |
|
---|
927 | \image linguist-previewtool.png
|
---|
928 |
|
---|
929 | Forms created by \e{Qt Designer} are stored in special UI files.
|
---|
930 | \QL can make use of these UI files to show the translations
|
---|
931 | done so far on the form itself. This of course requires access to the UI
|
---|
932 | files during the translation process. Activate
|
---|
933 | \menu{Tools|Open/Refresh Form Preview} to open the window shown above.
|
---|
934 | The list of UI files \QL has detected are displayed in the Forms
|
---|
935 | List on the left hand. If the path to the files has changed, you can load
|
---|
936 | the files manually via \menu{File|Open Form...}. Double-click on an entry
|
---|
937 | in the Forms List to display the Form File. Select \e{<No Translation>} from
|
---|
938 | the toolbar to display the untranslated form.
|
---|
939 |
|
---|
940 | \section1 Qt Linguist Reference
|
---|
941 |
|
---|
942 |
|
---|
943 | \section2 File Types
|
---|
944 |
|
---|
945 | \QL makes use of four kinds of files:
|
---|
946 |
|
---|
947 | \list
|
---|
948 | \o TS \e {translation source files} \BR are human-readable XML
|
---|
949 | files containing source phrases and their translations. These files are
|
---|
950 | usually created and updated by \l lupdate and are specific to an
|
---|
951 | application.
|
---|
952 | \o \c .xlf \e {XLIFF files} \BR are human-readable XML files that adhere
|
---|
953 | to the international XML Localization Interchange File Format. \QL
|
---|
954 | can be used to edit XLIFF files generated by other programs. However, for
|
---|
955 | standard Qt projects, only the TS file format is used. \note The minimum
|
---|
956 | supported version for XLIFF format files is 1.1. XLIFF 1.0 version files
|
---|
957 | are not supported.
|
---|
958 | \o QM \e {Qt message files} \BR are binary files that contain
|
---|
959 | translations used by an application at run-time. These files are
|
---|
960 | generated by \l lrelease, but can also be generated by \QL.
|
---|
961 | \o \c .qph \e {Qt phrase book files} \BR are human-readable XML
|
---|
962 | files containing standard phrases and their translations. These files
|
---|
963 | are created and updated by \QL and may be used by any
|
---|
964 | number of projects and applications.
|
---|
965 | \endlist
|
---|
966 |
|
---|
967 | \target menubar
|
---|
968 | \section2 The Menu Bar
|
---|
969 |
|
---|
970 | \image linguist-menubar.png
|
---|
971 |
|
---|
972 | \list
|
---|
973 | \o \gui {File}
|
---|
974 | \list
|
---|
975 | \o \gui {Open... Ctrl+O} \BR pops up an open file dialog from which a
|
---|
976 | translation source \c .ts or \c .xlf file can be chosen.
|
---|
977 | \o \gui {Recently opened files} \BR shows the TS files that
|
---|
978 | have been opened recently, click one to open it.
|
---|
979 | \o \gui {Save Ctrl+S} \BR saves the current translation source file.
|
---|
980 | \o \gui {Save As...} \BR pops up a save as file dialog so that the
|
---|
981 | current translation source file may be saved with a different
|
---|
982 | name, format and/or put in a different location.
|
---|
983 | \o \gui {Release} \BR create a Qt message QM file with the same base
|
---|
984 | name as the current translation source file. The release manager's
|
---|
985 | command line tool \l lrelease performs the same function on
|
---|
986 | \e all of an application's translation source files.
|
---|
987 | \o \gui {Release As...} \BR pops up a save as file dialog. The
|
---|
988 | filename entered will be a Qt message QM file of the translation
|
---|
989 | based on the current translation source file. The release manager's
|
---|
990 | command line tool \l lrelease performs the same function on
|
---|
991 | \e all of an application's translation source files.
|
---|
992 | \o \gui {Print... Ctrl+P} \BR pops up a print dialog. If you click
|
---|
993 | OK the translation source and the translations will be printed.
|
---|
994 | \o \gui {Exit Ctrl+Q} \BR closes \QL.
|
---|
995 | \endlist
|
---|
996 |
|
---|
997 | \o \gui {Edit}
|
---|
998 | \list
|
---|
999 | \o \gui {Undo Ctrl+Z} \BR undoes the last editing action in the
|
---|
1000 | translation pane.
|
---|
1001 | \o \gui {Redo Ctrl+Y} \BR redoes the last editing action in the
|
---|
1002 | translation pane.
|
---|
1003 | \o \gui {Cut Ctrl+X} \BR deletes any highlighted text in the
|
---|
1004 | translation pane and saves a copy to the clipboard.
|
---|
1005 | \o \gui {Copy Ctrl+C} \BR copies the highlighted text in the
|
---|
1006 | translation pane to the clipboard.
|
---|
1007 | \o \gui {Paste Ctrl+V} \BR pastes the clipboard text into the
|
---|
1008 | translation pane.
|
---|
1009 | \omit
|
---|
1010 | \o \gui {Delete} \BR deletes the highlighted text in the
|
---|
1011 | translation pane.
|
---|
1012 | \endomit
|
---|
1013 | \o \gui {Select All Ctrl+A} \BR selects all the text in the
|
---|
1014 | translation pane ready for copying or deleting.
|
---|
1015 | \o \gui {Find... Ctrl+F} \BR pops up the
|
---|
1016 | Find dialog. When the dialog pops up
|
---|
1017 | enter the text to be found and click the \gui {Find Next} button.
|
---|
1018 | Source phrases, translations and comments may be searched.
|
---|
1019 | \o \gui {Find Next F3} \BR finds the next occurrence of the text that
|
---|
1020 | was last entered in the Find dialog.
|
---|
1021 | \o \gui {Search and Translate...} \BR pops up the Search and
|
---|
1022 | Replace Dialog. Use this dialog to translate the same text in multiple items.
|
---|
1023 | \o \gui {Translation File Settings...} \BR let you configure the target
|
---|
1024 | language and the country/region of a translation source file.
|
---|
1025 | \endlist
|
---|
1026 |
|
---|
1027 | \o \gui {Translation}
|
---|
1028 | \list
|
---|
1029 | \o \gui {Prev Unfinished Ctrl+K} \BR moves to the nearest previous
|
---|
1030 | unfinished source phrase (unfinished means untranslated or
|
---|
1031 | translated but failed validation).
|
---|
1032 | \o \gui {Next Unfinished Ctrl+L} \BR moves to the next unfinished source
|
---|
1033 | phrase.
|
---|
1034 | \o \gui {Prev Shift+Ctrl+K} \BR moves to the previous source phrase.
|
---|
1035 | \o \gui {Next Shift+Ctrl+L} \BR moves to the next source phrase.
|
---|
1036 | \o \gui {Done \& Next Ctrl+Enter} \BR mark this phrase as 'done'
|
---|
1037 | (translated) and move to the next unfinished source phrase.
|
---|
1038 | \o \gui {Copy from source text Ctrl+B} \BR copies the source text into
|
---|
1039 | the translation.
|
---|
1040 | \endlist
|
---|
1041 |
|
---|
1042 | \o \gui {Validation} (See \l{Validation Tests})
|
---|
1043 | \list
|
---|
1044 | \o \gui {Accelerators} \BR toggles validation on or off for Alt
|
---|
1045 | accelerators.
|
---|
1046 | \o \gui {Ending Punctuation} \BR switches validation on or off
|
---|
1047 | for phrase ending punctuation, e.g. ellipsis, exclamation mark,
|
---|
1048 | question mark, etc.
|
---|
1049 | \o \gui {Phrase Matches} \BR sets validation on or off for
|
---|
1050 | matching against translations that are in the current phrase book.
|
---|
1051 | \o \gui {Place Marker Matches} \BR sets validation on or off for
|
---|
1052 | the use of the same place markers in the source and translation.
|
---|
1053 | \endlist
|
---|
1054 |
|
---|
1055 | \o \gui {Phrases} (See the section \l {Phrase Books} for details.)
|
---|
1056 | \list
|
---|
1057 |
|
---|
1058 | \o \gui {New Phrase Book... Ctrl+N} \BR pops up a save as file
|
---|
1059 | dialog. You must enter a filename to be used for the phrase
|
---|
1060 | book and save the file. Once saved you should open the phrase
|
---|
1061 | book to begin using it.
|
---|
1062 |
|
---|
1063 | \o \gui {Open Phrase Book... Ctrl+H} \BR pops up an open file
|
---|
1064 | dialog. Find and choose a phrase book to open.
|
---|
1065 |
|
---|
1066 | \o \gui {Close Phrase Book} \BR displays the list of phrase
|
---|
1067 | books currently opened. Clicking on one of the items will
|
---|
1068 | close the phrase book. If the phrase book has been modified, a
|
---|
1069 | dialog box asks whether \QL should save the changes.
|
---|
1070 |
|
---|
1071 | \o \gui {Edit Phrase Book...} \BR displays the list of phrase
|
---|
1072 | books currently opened. Clicking on one of the items will open
|
---|
1073 | the \l{Creating and Editing Phrase Books}{Phrase Book Dialog}
|
---|
1074 | where you can add, edit or delete phrases.
|
---|
1075 |
|
---|
1076 | \o \gui {Print Phrase Book...} \BR displays the list of phrase
|
---|
1077 | books currently opened. Clicking on one of the items pops up a
|
---|
1078 | print dialog. If you click OK the phrase book will be
|
---|
1079 | printed.
|
---|
1080 |
|
---|
1081 | \o \gui {Add to Phrase Book Ctrl+T} \BR Adds the source text
|
---|
1082 | and translation currently shown in the \l{The Translation
|
---|
1083 | Area} {translation area} to a phrase book. If multiple phrase
|
---|
1084 | books are loaded, a dialog box let you specify select one.
|
---|
1085 |
|
---|
1086 | \endlist
|
---|
1087 |
|
---|
1088 | \o \gui {Tools}
|
---|
1089 | \list
|
---|
1090 |
|
---|
1091 | \o \gui {Batch Translation...} \BR Opens a \l{Batch
|
---|
1092 | Translation}{dialog} which let you automatically insert
|
---|
1093 | translations for source texts which are in a phrase book.
|
---|
1094 |
|
---|
1095 | \o \gui {Open/Refresh Form Preview F3} \BR Opens the \l{Form
|
---|
1096 | Preview}. This window let you instantly see translations for
|
---|
1097 | forms created with \QD. \endlist
|
---|
1098 |
|
---|
1099 | \o \gui {View}
|
---|
1100 | \list
|
---|
1101 |
|
---|
1102 | \o \gui {Revert Sorting} \BR puts the items in the \l{Context
|
---|
1103 | Window} {context list} and in the \l{Strings Window} {string
|
---|
1104 | list} into their original order.
|
---|
1105 |
|
---|
1106 | \o \gui {Display Guesses} \BR turns the display of phrases and
|
---|
1107 | guesses on or off.
|
---|
1108 |
|
---|
1109 | \o \gui {Statistics} \BR toggles the visibility of the
|
---|
1110 | Statistics dialog.
|
---|
1111 |
|
---|
1112 | \o \gui {Views} \BR toggles the visibility of the \l{Context
|
---|
1113 | Window}, \l{Strings Window}, \l{Phrases and Guesses Window},
|
---|
1114 | \l{Warnings Window}, or \l{Sources and Forms Window}.
|
---|
1115 |
|
---|
1116 | \o \gui {Toolbars} \BR toggles the visibility of the different
|
---|
1117 | toolbars.
|
---|
1118 |
|
---|
1119 | \endlist
|
---|
1120 |
|
---|
1121 | \o \gui {Help}
|
---|
1122 | \list
|
---|
1123 | \o \gui {Manual F1} \BR opens this manual.
|
---|
1124 | \o \gui {About Qt Linguist} \BR Shows information about \QL.
|
---|
1125 | \o \gui {About Qt} \BR Shows information about \e{Qt}.
|
---|
1126 | \o \gui {What's This? Shift+F1} \BR Click on one item in the main window
|
---|
1127 | to get additional information about it.
|
---|
1128 | \endlist
|
---|
1129 |
|
---|
1130 | \endlist
|
---|
1131 |
|
---|
1132 | \section2 The Toolbar
|
---|
1133 |
|
---|
1134 | \image linguist-toolbar.png
|
---|
1135 |
|
---|
1136 | \list
|
---|
1137 | \o \inlineimage linguist-fileopen.png
|
---|
1138 | \BR
|
---|
1139 | Pops up the open file dialog to open a new translation source TS file.
|
---|
1140 |
|
---|
1141 | \o \inlineimage linguist-filesave.png
|
---|
1142 | \BR
|
---|
1143 | Saves the current translation source TS file.
|
---|
1144 |
|
---|
1145 | \o \inlineimage linguist-fileprint.png
|
---|
1146 | \BR
|
---|
1147 | Prints the current translation source TS file.
|
---|
1148 |
|
---|
1149 | \o \inlineimage linguist-phrasebookopen.png
|
---|
1150 | \BR
|
---|
1151 | Pops up the file open dialog to open a new phrase book \c .qph file.
|
---|
1152 |
|
---|
1153 | \o \inlineimage linguist-editundo.png
|
---|
1154 | \BR
|
---|
1155 | Undoes the last editing action in the translation pane.
|
---|
1156 |
|
---|
1157 | \o \inlineimage linguist-editredo.png
|
---|
1158 | \BR
|
---|
1159 | Redoes the last editing action in the translation pane.
|
---|
1160 |
|
---|
1161 | \o \inlineimage linguist-editcut.png
|
---|
1162 | \BR
|
---|
1163 | Deletes any highlighted text in the translation pane and save a copy to
|
---|
1164 | the clipboard.
|
---|
1165 |
|
---|
1166 | \o \inlineimage linguist-editcopy.png
|
---|
1167 | \BR
|
---|
1168 | Copies the highlighted text in the translation pane to the clipboard.
|
---|
1169 |
|
---|
1170 | \o \inlineimage linguist-editpaste.png
|
---|
1171 | \BR
|
---|
1172 | Pastes the clipboard text into the translation pane.
|
---|
1173 |
|
---|
1174 | \o \inlineimage linguist-editfind.png
|
---|
1175 | \BR
|
---|
1176 | Pops up the Find dialog .
|
---|
1177 |
|
---|
1178 | \o \inlineimage linguist-prev.png
|
---|
1179 | \BR
|
---|
1180 | Moves to the previous source phrase.
|
---|
1181 |
|
---|
1182 | \o \inlineimage linguist-next.png
|
---|
1183 | \BR
|
---|
1184 | Moves to the next source phrase.
|
---|
1185 |
|
---|
1186 | \o \inlineimage linguist-prevunfinished.png
|
---|
1187 | \BR
|
---|
1188 | Moves to the previous unfinished source phrase.
|
---|
1189 |
|
---|
1190 | \o \inlineimage linguist-nextunfinished.png
|
---|
1191 | \BR
|
---|
1192 | Moves to the next unfinished source phrase.
|
---|
1193 |
|
---|
1194 | \o \inlineimage linguist-doneandnext.png
|
---|
1195 | \BR
|
---|
1196 | Marks the phrase as 'done' (translated) and move to the next
|
---|
1197 | unfinished source phrase.
|
---|
1198 |
|
---|
1199 | \o \inlineimage linguist-validateaccelerators.png
|
---|
1200 | \BR
|
---|
1201 | Toggles accelerator validation on and off.
|
---|
1202 |
|
---|
1203 | \o \inlineimage linguist-validatepunctuation.png
|
---|
1204 | \BR
|
---|
1205 | Toggles phrase ending punctuation validation on and off.
|
---|
1206 |
|
---|
1207 | \o \inlineimage linguist-validatephrases.png
|
---|
1208 | \BR
|
---|
1209 | Toggles phrase book validation on or off.
|
---|
1210 |
|
---|
1211 | \o \inlineimage linguist-validateplacemarkers.png
|
---|
1212 | \BR
|
---|
1213 | Toggles place marker validation on or off.
|
---|
1214 |
|
---|
1215 | \endlist
|
---|
1216 |
|
---|
1217 | */
|
---|
1218 |
|
---|
1219 | /*!
|
---|
1220 | \page linguist-programmers.html
|
---|
1221 | \title Qt Linguist Manual: Programmers
|
---|
1222 |
|
---|
1223 | \contentspage {Qt Linguist Manual}{Contents}
|
---|
1224 | \previouspage Qt Linguist Manual: Translators
|
---|
1225 | \nextpage Qt Linguist Manual: TS File Format
|
---|
1226 |
|
---|
1227 | Support for multiple languages is extremely simple in Qt
|
---|
1228 | applications, and adds little overhead to the programmer's workload.
|
---|
1229 |
|
---|
1230 | Qt minimizes the performance cost of using translations by
|
---|
1231 | translating the phrases for each window as they are created. In most
|
---|
1232 | applications the main window is created just once. Dialogs are often
|
---|
1233 | created once and then shown and hidden as required. Once the initial
|
---|
1234 | translation has taken place there is no further runtime overhead for
|
---|
1235 | the translated windows. Only those windows that are created,
|
---|
1236 | destroyed and subsequently created will have a translation
|
---|
1237 | performance cost.
|
---|
1238 |
|
---|
1239 | Creating applications that can switch language at runtime is possible
|
---|
1240 | with Qt, but requires a certain amount of programmer intervention and
|
---|
1241 | will of course incur some runtime performance cost.
|
---|
1242 |
|
---|
1243 | \section1 Making the Application Translation-Aware
|
---|
1244 |
|
---|
1245 | Programmers should make their application look for and load the
|
---|
1246 | appropriate translation file and mark user-visible text and Ctrl
|
---|
1247 | keyboard accelerators as targets for translation.
|
---|
1248 |
|
---|
1249 | Each piece of text that requires translating requires context to help
|
---|
1250 | the translator identify where in the program the text occurs. In the
|
---|
1251 | case of multiple identical texts that require different translations,
|
---|
1252 | the translator also requires some information to disambiguate the
|
---|
1253 | source texts. Marking text for translation will automatically cause
|
---|
1254 | the class name to be used as basic context information. In some cases
|
---|
1255 | the programmer may be required to add additional information to help
|
---|
1256 | the translator.
|
---|
1257 |
|
---|
1258 | \section2 Creating Translation Files
|
---|
1259 |
|
---|
1260 | Translation files consist of all the user-visible text and Ctrl key
|
---|
1261 | accelerators in an application and translations of that text.
|
---|
1262 | Translation files are created as follows:
|
---|
1263 |
|
---|
1264 | \list 1
|
---|
1265 | \o Run \l lupdate initially to generate the first set of TS
|
---|
1266 | translation source files with all the user-visible text but no
|
---|
1267 | translations.
|
---|
1268 | \o The TS files are given to the translator who adds translations
|
---|
1269 | using \QL. \QL takes care of any changed
|
---|
1270 | or deleted source text.
|
---|
1271 | \o Run \l lupdate to incorporate any new text added to the
|
---|
1272 | application. \l lupdate synchronizes the user-visible text from the
|
---|
1273 | application with the translations; it does not destroy any data.
|
---|
1274 | \o Steps 2 and 3 are repeated as often as necessary.
|
---|
1275 | \o When a release of the application is needed \l lrelease is run to
|
---|
1276 | read the TS files and produce the QM files used by the
|
---|
1277 | application at runtime.
|
---|
1278 | \endlist
|
---|
1279 |
|
---|
1280 | For \l lupdate to work successfully, it must know which translation
|
---|
1281 | files to produce. The files are simply listed in the application's \c
|
---|
1282 | .pro Qt project file, for example:
|
---|
1283 |
|
---|
1284 | \snippet examples/linguist/arrowpad/arrowpad.pro 1
|
---|
1285 |
|
---|
1286 | If your sources contain genuine non-Latin1 strings, \l lupdate needs
|
---|
1287 | to be told about it in the \c .pro file by using, for example,
|
---|
1288 | the following line:
|
---|
1289 |
|
---|
1290 | \code
|
---|
1291 | CODECFORTR = UTF-8
|
---|
1292 | \endcode
|
---|
1293 |
|
---|
1294 | See the \l lupdate and \l lrelease sections.
|
---|
1295 |
|
---|
1296 | \section2 Loading Translations
|
---|
1297 |
|
---|
1298 | \snippet examples/linguist/hellotr/main.cpp 1
|
---|
1299 | \snippet examples/linguist/hellotr/main.cpp 3
|
---|
1300 |
|
---|
1301 | This is how a simple \c main() function of a Qt application begins.
|
---|
1302 |
|
---|
1303 | \snippet examples/linguist/hellotr/main.cpp 1
|
---|
1304 | \snippet examples/linguist/hellotr/main.cpp 4
|
---|
1305 |
|
---|
1306 | For a translation-aware application a translator object is created, a
|
---|
1307 | translation is loaded and the translator object installed into the
|
---|
1308 | application.
|
---|
1309 |
|
---|
1310 | \snippet examples/linguist/arrowpad/main.cpp 0
|
---|
1311 | \snippet examples/linguist/arrowpad/main.cpp 1
|
---|
1312 |
|
---|
1313 | For non-Latin1 strings in the sources you will also need for example:
|
---|
1314 |
|
---|
1315 | \code
|
---|
1316 | QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));
|
---|
1317 | \endcode
|
---|
1318 |
|
---|
1319 | In production applications a more flexible approach, for example,
|
---|
1320 | loading translations according to locale, might be more appropriate. If
|
---|
1321 | the TS files are all named according to a convention such as
|
---|
1322 | \e appname_locale, e.g. \c tt2_fr, \c tt2_de etc, then the
|
---|
1323 | code above will load the current locale's translation at runtime.
|
---|
1324 |
|
---|
1325 | If there is no translation file for the current locale the application
|
---|
1326 | will fall back to using the original source text.
|
---|
1327 |
|
---|
1328 | Note that if you need to programmatically add translations at
|
---|
1329 | runtime, you can reimplement QTranslator::translate().
|
---|
1330 |
|
---|
1331 | \section2 Making the Application Translate User-Visible Strings
|
---|
1332 |
|
---|
1333 | User-visible strings are marked as translation targets by wrapping them
|
---|
1334 | in a \c tr() call, for example:
|
---|
1335 |
|
---|
1336 | \snippet doc/src/snippets/code/doc_src_linguist-manual.qdoc 6
|
---|
1337 |
|
---|
1338 | would become
|
---|
1339 |
|
---|
1340 | \snippet doc/src/snippets/code/doc_src_linguist-manual.qdoc 7
|
---|
1341 |
|
---|
1342 | All QObject subclasses that use the \c Q_OBJECT macro implement
|
---|
1343 | the \c tr() function.
|
---|
1344 |
|
---|
1345 | Although the \c tr() call is normally made directly since it is
|
---|
1346 | usually called as a member function of a QObject subclass, in
|
---|
1347 | other cases an explicit class name can be supplied, for example:
|
---|
1348 |
|
---|
1349 | \snippet doc/src/snippets/code/doc_src_linguist-manual.qdoc 8
|
---|
1350 |
|
---|
1351 | or
|
---|
1352 |
|
---|
1353 | \snippet doc/src/snippets/code/doc_src_linguist-manual.qdoc 9
|
---|
1354 |
|
---|
1355 | \section2 Distinguishing Between Identical Translatable Strings
|
---|
1356 |
|
---|
1357 | The \l lupdate program automatically provides a \e context for every
|
---|
1358 | source text. This context is the class name of the class that contains
|
---|
1359 | the \c tr() call. This is sufficient in the vast majority of cases.
|
---|
1360 | Sometimes however, the translator will need further information to
|
---|
1361 | uniquely identify a source text; for example, a dialog that contained
|
---|
1362 | two separate frames, each of which contained an "Enabled" option would
|
---|
1363 | need each identified because in some languages the translation would
|
---|
1364 | differ between the two. This is easily achieved using the
|
---|
1365 | two argument form of the \c tr() call, e.g.
|
---|
1366 |
|
---|
1367 | \snippet doc/src/snippets/code/doc_src_linguist-manual.qdoc 10
|
---|
1368 |
|
---|
1369 | and
|
---|
1370 |
|
---|
1371 | \snippet doc/src/snippets/code/doc_src_linguist-manual.qdoc 11
|
---|
1372 |
|
---|
1373 | Ctrl key accelerators are also translatable:
|
---|
1374 |
|
---|
1375 | \snippet examples/linguist/trollprint/mainwindow.cpp 2
|
---|
1376 |
|
---|
1377 | It is strongly recommended that the two argument form of \c tr() is used
|
---|
1378 | for Ctrl key accelerators. The second argument is the only clue the
|
---|
1379 | translator has as to the function performed by the accelerator.
|
---|
1380 |
|
---|
1381 | \section2 Helping the Translator with Navigation Information
|
---|
1382 |
|
---|
1383 | In large complex applications it may be difficult for the translator to
|
---|
1384 | see where a particular source text comes from. This problem can be
|
---|
1385 | solved by adding a comment using the keyword \e TRANSLATOR which
|
---|
1386 | describes the navigation steps to reach the text in question; e.g.
|
---|
1387 |
|
---|
1388 | \snippet doc/src/snippets/code/doc_src_linguist-manual.qdoc 12
|
---|
1389 |
|
---|
1390 | These comments are particularly useful for widget classes.
|
---|
1391 |
|
---|
1392 | \section2 Handling Plural Forms
|
---|
1393 |
|
---|
1394 | Qt includes a \c tr() overload that will make it very easy to
|
---|
1395 | write "plural-aware" internationalized applications. This overload
|
---|
1396 | has the following signature:
|
---|
1397 |
|
---|
1398 | \snippet doc/src/snippets/code/doc_src_linguist-manual.qdoc 17
|
---|
1399 |
|
---|
1400 | Depending on the value of \c n, the \c tr() function will return a different
|
---|
1401 | translation, with the correct grammatical number for the target language.
|
---|
1402 | Also, any occurrence of \c %n is replaced with \c{n}'s value. For example:
|
---|
1403 |
|
---|
1404 | \snippet doc/src/snippets/code/doc_src_linguist-manual.qdoc 18
|
---|
1405 |
|
---|
1406 | If a French translation is loaded, this will expand to "0 item
|
---|
1407 | remplac\unicode{233}", "1 item remplac\unicode{233}", "2 items
|
---|
1408 | remplac\unicode{233}s", etc., depending on \c{n}'s value.
|
---|
1409 | And if no translation is loaded, the orignal string is used, with \c %n
|
---|
1410 | replaced with count's value (e.g., "6 item(s) replaced").
|
---|
1411 |
|
---|
1412 | To handle plural forms in the native language, you need to load a
|
---|
1413 | translation file for this language, too. \l lupdate has the
|
---|
1414 | \c -pluralonly command line option, which allows the creation of
|
---|
1415 | TS files containing only entries with plural forms.
|
---|
1416 |
|
---|
1417 | See the \l{http://doc.qt.nokia.com/qq/}{Qt Quarterly} Article
|
---|
1418 | \l{http://doc.qt.nokia.com/qq/qq19-plurals.html}{Plural Forms in Translations}
|
---|
1419 | for further details on this issue.
|
---|
1420 |
|
---|
1421 | \section2 Coping With C++ Namespaces
|
---|
1422 |
|
---|
1423 | C++ namespaces and the \c {using namespace} statement can confuse
|
---|
1424 | \l lupdate. It will interpret \c MyClass::tr() as meaning just
|
---|
1425 | that, not as \c MyNamespace::MyClass::tr(), even if \c MyClass is
|
---|
1426 | defined in the \c MyNamespace namespace. Runtime translation of
|
---|
1427 | these strings will fail because of that.
|
---|
1428 |
|
---|
1429 | You can work around this limitation by putting a \e TRANSLATOR
|
---|
1430 | comment at the beginning of the source files that use \c
|
---|
1431 | MyClass::tr():
|
---|
1432 |
|
---|
1433 | \snippet doc/src/snippets/code/doc_src_linguist-manual.qdoc 13
|
---|
1434 |
|
---|
1435 | After the comment, all references to \c MyClass::tr() will be
|
---|
1436 | understood as meaning \c MyNamespace::MyClass::tr().
|
---|
1437 |
|
---|
1438 | \section2 Translating Text That is Outside of a QObject Subclass
|
---|
1439 |
|
---|
1440 | \section3 Using QCoreApplication::translate()
|
---|
1441 |
|
---|
1442 | If the quoted text is not in a member function of a QObject subclass,
|
---|
1443 | use either the tr() function of an appropriate class, or the
|
---|
1444 | QCoreApplication::translate() function directly:
|
---|
1445 |
|
---|
1446 | \snippet doc/src/snippets/code/doc_src_linguist-manual.qdoc 14
|
---|
1447 |
|
---|
1448 | \section3 Using QT_TR_NOOP() and QT_TRANSLATE_NOOP()
|
---|
1449 |
|
---|
1450 | If you need to have translatable text completely outside a function,
|
---|
1451 | there are two macros to help: QT_TR_NOOP() and QT_TRANSLATE_NOOP().
|
---|
1452 | These macros merely mark the text for extraction by \l{lupdate}.
|
---|
1453 | The macros expand to just the text (without the context).
|
---|
1454 |
|
---|
1455 | Example of QT_TR_NOOP():
|
---|
1456 | \snippet doc/src/snippets/code/doc_src_linguist-manual.qdoc 15
|
---|
1457 |
|
---|
1458 | Example of QT_TRANSLATE_NOOP():
|
---|
1459 | \snippet doc/src/snippets/code/doc_src_linguist-manual.qdoc 16
|
---|
1460 |
|
---|
1461 | \section1 Tutorials
|
---|
1462 |
|
---|
1463 | Three tutorials are presented:
|
---|
1464 |
|
---|
1465 | \list 1
|
---|
1466 | \o \l{linguist/hellotr}{Hello tr()} demonstrates the creation of
|
---|
1467 | a \l QTranslator object. It also shows the simplest use of
|
---|
1468 | the \c tr() function to mark user-visible source text for
|
---|
1469 | translation.
|
---|
1470 |
|
---|
1471 | \o \l{linguist/arrowpad}{Arrow Pad} explains how to make the application load the
|
---|
1472 | translation file applicable to the current locale. It also shows the
|
---|
1473 | use of the two-argument form of \c tr() which provides additional
|
---|
1474 | information to the translator.
|
---|
1475 |
|
---|
1476 | \o \l{linguist/trollprint}{Troll Print} explains how
|
---|
1477 | identical source texts can be distinguished even when they occur in
|
---|
1478 | the same context. This tutorial also discusses how the translation
|
---|
1479 | tools help minimize the translator's work when an application is
|
---|
1480 | upgraded.
|
---|
1481 | \endlist
|
---|
1482 |
|
---|
1483 | These tutorials cover all that you need to know to prepare your Qt
|
---|
1484 | applications for translation.
|
---|
1485 |
|
---|
1486 | At the beginning of a project add the translation source files to be
|
---|
1487 | used to the project file and add calls to \l lupdate and \l lrelease to
|
---|
1488 | the makefile.
|
---|
1489 |
|
---|
1490 | During the project all the programmer must do is wrap any user-visible
|
---|
1491 | text in \c tr() calls. They should also use the two argument form for
|
---|
1492 | Ctrl key accelerators, or when asked by the translator for the cases
|
---|
1493 | where the same text translates into two different forms in the same
|
---|
1494 | context. The programmer should also include \c TRANSLATION comments to
|
---|
1495 | help the translator navigate the application.
|
---|
1496 | */
|
---|
1497 |
|
---|
1498 | /*!
|
---|
1499 | \page linguist-ts-file-format.html
|
---|
1500 | \title Qt Linguist Manual: TS File Format
|
---|
1501 |
|
---|
1502 | \contentspage {Qt Linguist Manual}{Contents}
|
---|
1503 | \previouspage Qt Linguist Manual: Programmers
|
---|
1504 |
|
---|
1505 | The TS file format used by \QL is described by the
|
---|
1506 | \l{http://www.w3.org/TR/1998/REC-xml-19980210}{DTD} presented below,
|
---|
1507 | which we include for your convenience. Be aware that the format
|
---|
1508 | may change in future Qt releases.
|
---|
1509 |
|
---|
1510 | \quotefile tools/linguist/shared/ts.dtd
|
---|
1511 |
|
---|
1512 | */
|
---|