Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
linguist-manual.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2023 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\page qtlinguist-index.html
6
\title Qt Linguist Manual
7
\ingroup qttools
8
\ingroup internationalization
9
\brief Using Qt translation tools: lupdate, lrelease, and \QL.
10
11
\startpage {index.html}{Qt Reference Documentation}
12
\nextpage Release managers
13
14
\keyword Qt Linguist
15
16
Release managers, translators, and developers can use Qt tools to translate
17
Qt C++ and Qt Quick applications into local languages.
18
19
In addition to the Qt translation file (TS) format, \QL and \c lupdate
20
support XML Localization Interchange File Format (XLIFF).
21
22
\table
23
\row
24
\li \inlineimage front-publishing.png {Icon showing an publishing action}
25
\li \inlineimage front-ui.png {UI illustration showing Start buttons,
26
toggle controls, and a circular selector on a dark
27
screen}
28
\li \inlineimage front-coding.png {Illustration showing a code}
29
\row
30
\li \l{Release managers}
31
\li \l{Translators}
32
\li \l{Developers}
33
\row
34
\li
35
\list
36
\li \l {Creating translation files}
37
\li \l {Using lupdate}
38
\li \l {Using lrelease}
39
\li \l {Using lupdate-pro}
40
\li \l {Using lrelease-pro}
41
\li \l {Using lconvert}
42
\li \l {Using lcheck}
43
\li \l {Using ltext2id}
44
\endlist
45
\li
46
\list
47
\li \l {Qt Linguist user interface}
48
\li \l {Translating strings}
49
\li \l {Selecting context or label to translate}
50
\li \l {Selecting strings to translate}
51
\li \l {Viewing strings in context}
52
\li \l {Reusing translations}
53
\li \l {Validating translations}
54
\li \l {Translating multiple languages simultaneously}
55
\li \l {AI translation}
56
\endlist
57
\li
58
\list
59
\li \l{TS file format}
60
\li \l{Text ID based translations}
61
\li \l{Meta strings reference}
62
\li \l{CMake Commands in Qt6 LinguistTools}{CMake commands}
63
\li \l{Examples}
64
\endlist
65
\endtable
66
67
The following video shows how to internationalize and localize a simple
68
example application:
69
70
\youtube xNIz78IPBu0
71
*/
72
73
/*!
74
\page linguist-toc.html
75
\title All topics
76
77
\list
78
\li \l{Release managers}
79
\list
80
\li \l {Creating translation files}
81
\li \l {Using lupdate}
82
\li \l {Using lrelease}
83
\li \l {Using lupdate-pro}
84
\li \l {Using lrelease-pro}
85
\endlist
86
\li \l{Translators}
87
\list
88
\li \l {Qt Linguist user interface}
89
\li \l {Translating strings}
90
\li \l {Selecting context or label to translate}
91
\li \l {Selecting strings to translate}
92
\li \l {Viewing strings in context}
93
\li \l {Reusing translations}
94
\li \l {Validating translations}
95
\li \l {Translating multiple languages simultaneously}
96
\li \l {AI translation}
97
\endlist
98
\li \l{Developers}
99
\list
100
\li \l{TS file format}
101
\li \l{Text ID based translations}
102
\li \l{Meta strings reference}
103
\li \l{CMake Commands in Qt6 LinguistTools}{CMake commands}
104
\li \l{Examples}
105
\endlist
106
\endlist
107
*/
108
109
/*!
110
\page linguist-manager.html
111
\title Release managers
112
113
\previouspage Qt Linguist Manual
114
\nextpage Creating translation files
115
116
\image front-publishing.png {Icon showing an publishing action}
117
118
Release managers use \c lupdate to generate a set of translation source (TS)
119
files from the application source files (QML and C++) and pass them to
120
translators. The translators use \QL to translate the strings and pass the
121
TS files back to the release managers. They use \c lrelease to generate
122
compact versions of the TS files, called Qt message (QM) files, that are
123
ready for use by the application.
124
125
\list
126
\li \l {Creating translation files}
127
\li \l {Using lupdate}
128
\li \l {Using lrelease}
129
\endlist
130
131
You can use the tools in repeated cycles as applications change and evolve.
132
They preserve existing translations and make it easy to identify new strings.
133
In addition, you can use the \QL phrase books to consistently translate
134
multiple applications and projects.
135
136
You can configure CMake projects to automatically run \c lupdate and
137
\c lrelease when you build a project and generate TS and QM files for you.
138
139
You can use the Qt Design Studio
140
\l{https://doc-snapshots.qt.io/qtdesignstudio/studio-translations.html}
141
{Translations} view to test and manage \l {Text ID based translations}
142
{ID-based translations}.
143
*/
144
145
/*!
146
\page linguist-creating-ts-files.html
147
148
\previouspage Release managers
149
\nextpage Using lupdate
150
151
\title Creating translation files
152
153
Most of the text to translate in an application consists of either single
154
words or short phrases. These typically appear as window titles, menu
155
items, tooltips, and labels to buttons, check boxes, and radio buttons.
156
157
Developers mark the phrases as translatable in the QML and C++ source code.
158
The Qt tools provide context information for each of the phrases to help the
159
translator understand their meaning. The developer can add comments to the
160
phrases.
161
162
Translation files consist of all the user-visible text and \key Ctrl key
163
shortcuts in an application and translations of that text.
164
165
To create translation files:
166
167
\list 1
168
169
\li Run \c lupdate to generate the first set of translation source (TS)
170
files with all the user-visible text but no translations.
171
172
\li Give the TS files to translators who add translations using \QL.
173
\QL indicates changed and deleted source text.
174
175
\li Run \c lupdate to incorporate any new text added to the application.
176
\c lupdate synchronizes the user-visible text from the application
177
with the translations. Existing translations in the TS file are
178
preserved.
179
180
\li Run \c lrelease to read the TS files and produce the QM files used
181
by the application at runtime.
182
183
\endlist
184
185
For \c lupdate to work successfully, it must know which translation files to
186
produce. Specify the files in the application's Qt project file.
187
188
When building with CMake, you use \l{CMake Commands in Qt6 LinguistTools}
189
{CMake commands} to add targets that create or update TS files and transform
190
them into QM files. The translation files are generated when you build the
191
targets.
192
*/
193
194
/*!
195
\page linguist-lupdate.html
196
\target lupdate
197
198
\previouspage Release managers
199
\nextpage Using lrelease
200
201
\title Using lupdate
202
203
The \c lupdate command line tool finds translatable strings in C++ source,
204
C++ header, Java, Python, QML, and UI files and generates or updates TS
205
files.
206
207
When building with qmake, specify the files to process at the command line
208
or in a .pro file.
209
210
When building with CMake, use \l{CMake Commands in Qt6 LinguistTools}
211
{CMake commands} to add targets that create or update TS files and transform
212
them into QM files. The \c lupdate tool is run with the \l {lupdate options}
213
{options} you pass to the commands when you build the target.
214
215
For more information about specifying translations in project files, see
216
\l{Localizing Applications}.
217
218
\section1 lupdate syntax
219
220
\badcode
221
lupdate [options] [project-file]...
222
lupdate [options] [source-file|path|@lst-file]... -ts ts-files|@lst-file
223
\endcode
224
225
Where:
226
227
\list
228
\li \c options means one or several \l {lupdate options}.
229
\li \c project-file is the project configuration file.
230
\li \c source-file is a file that contains translatable strings.
231
\li \c path is the path to a folder that contains translation
232
source files.
233
\li \c @lst-file reads additional file names (one per line) or
234
includepaths (one per line and prefixed with \c -I) from \e lst-file.
235
\li \c ts-files are the TS files to generate or update.
236
\endlist
237
238
To view the latest help, enter:
239
240
\badcode
241
lupdate -help
242
\endcode
243
244
\section2 lupdate options
245
246
\table
247
\header
248
\li Option
249
\li Action
250
\row
251
\li \c {-help}
252
\li Display up-to-date help information and exit.
253
\row
254
\li \c {-no-obsolete}
255
\li Drop all obsolete and vanished strings.
256
\row
257
\li \c {-extensions <ext>[,<ext>]...}
258
\li Process files with the given extensions, only. Use commas to
259
separate extensions in the list. Do not use whitespace. The default
260
value is:
261
\c {java,jui,ui,c,c++,cc,cpp,cxx,ch,h,h++,hh,hpp,hxx,js,qs,qml,qrc}.
262
\row
263
\li \c {-pluralonly}
264
\li Only include plural form messages.
265
\row
266
\li \c {-silent}
267
\li Do not explain what is being done.
268
\row
269
\li \c {-no-sort}
270
\li Do not sort contexts in TS files.
271
\row
272
\li \c {-sort-messages}
273
\li Sort messages in a context alphabetically in TS files.
274
\row
275
\li \c {-no-recursive}
276
\li Do not recursively scan directories.
277
\row
278
\li \c {-recursive}
279
\li Recursively scan directories (default).
280
\row
281
\li \c {-warnings-are-errors}
282
\li Treat warnings as errors.
283
\row
284
\li \c {-I <includepath> or -I<includepath>}
285
\li Look for include files in this additional location. You can specify
286
multiple paths.
287
\row
288
\li \c {-locations {absolute|relative|none}}
289
\li Specify or override the way to save source code references in TS
290
files.
291
\list
292
\li \c absolute means that the source file path is relative to
293
the target file, but the line number is absolute.
294
\li \c relative means that the source file path is relative to
295
the target file. The line number is relative to other
296
entries in the same source file.
297
\li \c none stores no information about source location.
298
\endlist
299
If you do not specify the location, \c lupdate determines it from
300
existing TS files. The default value for new files is \c absolute.
301
\row
302
\li \c {-no-ui-lines}
303
\li Do not record line numbers in references to UI files.
304
\row
305
\li \c {-disable-heuristic {sametext|similartext}}
306
\li Disable the named merge heuristic. Can be specified multiple times.
307
\row
308
\li \c {-project <filename>}
309
\li Name of a file containing the project's description in JSON format.
310
You can use \c{lupdate-pro -dump-json <file>} to generate the
311
file from a .pro file.
312
\row
313
\li \c {-pro <filename>}
314
\li Name of a .pro file. Useful for files with the .pro file syntax but
315
some other file suffix. Projects are recursed into and merged.
316
This option is deprecated. Use the \c lupdate-pro tool instead.
317
\row
318
\li \c {-pro-out <directory>}
319
\li Virtual output directory for processing subsequent .pro files.
320
\row
321
\li \c {-pro-debug}
322
\li Trace processing .pro files. Specify twice for more verbosity.
323
\row
324
\li \c {-source-language <language>[_<region>]}
325
\li Specify the language of the source strings for new files.
326
Defaults to POSIX if not specified.
327
\row
328
\li \c {-target-language <language>[_<region>]}
329
\li Specify the language of the translations for new files.
330
If you do not specify the language, \c lupdate determines it from
331
the file name.
332
\row
333
\li \c {-tr-function-alias <function>{+=,=}<alias>[,<function>{+=,=}<alias>]...}
334
\li With \c {+=}, recognize \c <alias> as an alternative spelling of
335
\c <function>.
336
With \c {=,} recognize \c <alias> as the only spelling of
337
\c <function>.
338
339
Available \c <function> values (with their currently defined aliases)
340
are:
341
\list
342
\li \c {Q_DECLARE_TR_FUNCTIONS} (\c {=Q_DECLARE_TR_FUNCTIONS})
343
\li \c {QT_TR_N_NOOP} (\c {=QT_TR_N_NOOP})
344
\li \c {QT_TRID_N_NOOP} (\c {=QT_TRID_N_NOOP})
345
\li \c {QT_TRANSLATE_N_NOOP} (\c {=QT_TRANSLATE_N_NOOP})
346
\li \c {QT_TRANSLATE_N_NOOP3} (\c {=QT_TRANSLATE_N_NOOP3})
347
\li \c {QT_TR_NOOP} (\c {=QT_TR_NOOP})
348
\li \c {QT_TRID_NOOP} (\c {=QT_TRID_NOOP})
349
\li \c {QT_TRANSLATE_NOOP} (\c {=QT_TRANSLATE_NOOP})
350
\li \c {QT_TRANSLATE_NOOP3} (\c {=QT_TRANSLATE_NOOP3})
351
\li \c {QT_TR_NOOP_UTF8} (\c {=QT_TR_NOOP_UTF8})
352
\li \c {QT_TRANSLATE_NOOP_UTF8} (\c {=QT_TRANSLATE_NOOP_UTF8})
353
\li \c {QT_TRANSLATE_NOOP3_UTF8} (\c {=QT_TRANSLATE_NOOP3_UTF8})
354
\li \c {findMessage} (\c {=findMessage})
355
\li \c {qtTrId} (\c {=qtTrId})
356
\li \c {tr} (\c {=tr})
357
\li \c {trUtf8} (\c {=trUtf8})
358
\li \c {translate} (\c {=translate})
359
\li \c {qsTr} (\c {=qsTr})
360
\li \c {qsTrId} (\c {=qsTrId})
361
\li \c {qsTranslate} (\c {=qsTranslate})
362
\endlist
363
\row
364
\li \c {-ts <ts-file>...}
365
\li Specify the output files. This overrides \c TRANSLATIONS.
366
\row
367
\li \c {-version}
368
\li Display the version of \c lupdate and exit.
369
\endtable
370
371
\section1 Examples
372
373
\section2 Using lupdate with CMake
374
375
When building with CMake, use \l{CMake Commands in Qt6 LinguistTools}
376
{CMake commands} to add translations on targets to the CMakeLists.txt
377
file, and then build the targets.
378
379
Select one of the following options:
380
381
\list
382
\li Use \l qt_add_translations on a target, such as \e app.
383
This calls \l qt_add_lupdate and \l qt_add_lrelease.
384
\li Use \c qt_add_lupdate on a target.
385
\endlist
386
387
Build a target (for example, \c app_lupdate) to update the .ts
388
files for it. To update the .ts files for all targets, build the
389
target \c {update_translations}.
390
391
\section2 Using lupdate with qmake
392
393
To generate a translation file for a single QML file:
394
395
\badcode
396
lupdate main.qml -ts main_en.ts
397
\endcode
398
399
To make a translation file for another language, for example French,
400
copy main_en.ts to main_fr.ts, and translate the strings in the
401
French TS file.
402
403
\c lupdate processes QML files that are listed in the \c .qrc file:
404
405
\badcode
406
RESOURCES += qml.qrc
407
\endcode
408
409
To have all QML files processed by \c lupdate:
410
411
\badcode
412
lupdate application.qrc -ts myapp_en.ts
413
\endcode
414
415
To process all QML files in the current working directory (or its subfolders)
416
without using a \c .qrc file:
417
418
\badcode
419
lupdate . -extensions qml -ts myapp_en.ts
420
\endcode
421
422
To check for translatable strings in both QML and C++ source files:
423
424
\badcode
425
lupdate qml.qrc filevalidator.cpp -ts myapp_en.ts
426
\endcode
427
428
To generate .ts files that will be used for English and French without
429
specifying the languages in the project file:
430
431
\badcode
432
lupdate qml.qrc filevalidator.cpp -ts myapp_en.ts myapp_fr.ts
433
\endcode
434
435
Give the TS files to the translator who uses \QL to read the files and
436
insert the translations.
437
438
\section1 XLIFF format files
439
440
The TS file format is a simple human-readable XML format that you
441
can use with version control systems. In addition, \c lupdate can
442
process Localization Interchange File Format (XLIFF) files (\c .xlf).
443
444
\note Only XLIFF versions 1.1 and 1.2 are currently supported.
445
446
You can open and edit XLIFF files in \QL.
447
*/
448
449
/*!
450
\page linguist-lrelease.html
451
\target lrelease
452
453
\previouspage Using lupdate
454
\nextpage Using lupdate-pro
455
456
\title Using lrelease
457
458
The \c lrelease command line tool produces QM files out of TS files. The
459
QM file format is a compact binary format that the localized application
460
uses. It provides extremely fast lookup for translations.
461
462
When building with qmake, specify the files to process at the command line
463
or in a .pro file.
464
465
When building with CMake, use \l{CMake Commands in Qt6 LinguistTools}
466
{CMake commands} to add targets that create or update TS files and
467
transform them into QM files. The \c lrelease tool is run with the
468
\l {lrelease options}{options} you pass to the commands when you build
469
the target.
470
471
Run \c lrelease whenever you want to release the application, from the
472
initial test version through to the final release version. The application
473
does not need QM files to run, but if they are available, the application
474
detects them and uses them automatically.
475
476
\note The \c lrelease tool only incorporates translations that you
477
mark as \e finished. Otherwise, it uses the original text instead.
478
479
\section1 lrelease syntax
480
481
\badcode
482
lrelease [options] -project project-file
483
lrelease [options] ts-files [-qm qm-file]
484
\endcode
485
486
Where:
487
488
\list
489
\li \c options means one or several \l {lrelease options}.
490
\li \c project-file is the project configuration file.
491
\li \c ts-files are the TS files to use as input for the QM files.
492
\li \c qm-file is the name of the QM file to generate.
493
\endlist
494
495
\note Passing .pro files to \c lrelease is deprecated. Use the
496
\c lrelease-pro tool or the \c lrelease.prf feature when using qmake.
497
498
To view the latest help, enter:
499
500
\badcode
501
lrelease -help
502
\endcode
503
504
\section2 lrelease options
505
506
\table
507
\header
508
\li Option
509
\li Action
510
\row
511
\li \c {-help}
512
\li Display up-to-date help information and exit.
513
\row
514
\li \c {-idbased}
515
\li Deprecated. The flag is not required anymore and will be removed
516
in a future version. It was used to enable ID based translation.
517
\row
518
\li \c {-compress}
519
\li Compress the QM files.
520
\row
521
\li \c {-nounfinished}
522
\li Do not include unfinished translations.
523
\row
524
\li \c {-fail-on-invalid}
525
\li Fail if translations failing the following checks are found:
526
\list
527
\li validity check of accelerators
528
\li validity check of surrounding whitespaces
529
\li validity check of ending punctuation
530
\li validity check of place markers
531
\endlist
532
To get more details refer to Qt Linguist help
533
\row
534
\li \c {-fail-on-unfinished}
535
\li Generate an error if unfinished translations are found
536
\row
537
\li \c {-removeidentical}
538
\li If the translated text is the same as the source text, exclude the
539
message.
540
\row
541
\li \c {-markuntranslated <prefix>}
542
\li If a message has no real translation, use the source text
543
prefixed with the given string instead.
544
\row
545
\li \c {-project <filename>}
546
\li Name of a file containing the project's description in JSON format.
547
You can use \c{lupdate-pro -dump-json} to generate the file from a .pro
548
file.
549
\row
550
\li \c {-silent}
551
\li Do not explain what is being done.
552
\row
553
\li \c {-verbose}
554
\li Explain what is being done (default).
555
\row
556
\li \c {-version}
557
\li Display the version of \c lrelease and exit.
558
\endtable
559
560
\section1 Examples
561
562
\section2 Using lrelease with CMake
563
564
When building with CMake, use \l{CMake Commands in Qt6 LinguistTools}
565
{CMake commands} to add translations on targets to the CMakeLists.txt
566
file, and then build the targets.
567
568
Select one of the following options:
569
570
\list
571
\li Use \l qt_add_translations on a target, such as \e app.
572
This calls \l qt_add_lupdate and \l qt_add_lrelease.
573
\li Use \c qt_add_lrelease on a target.
574
\endlist
575
576
Build a target (for example, \c app_lrelease) to update the .qm
577
files for it. To update the .qm files for all targets, build the
578
target \c {release_translations}.
579
580
\section2 Using lrelease with qmake
581
582
To run \c lrelease without specifying a project file:
583
584
\badcode
585
lrelease.exe main_en.ts languages\main_fr.ts
586
\endcode
587
*/
588
589
/*!
590
\page linguist-lupdate-pro.html
591
\target lupdate-pro
592
593
\previouspage Using lrelease
594
\nextpage Using lrelease-pro
595
596
\title Using lupdate-pro
597
598
The \c lupdate-pro command line tool extracts translatable strings from
599
qmake projects (.pro files) and updates TS files. It is specifically
600
designed for qmake-based projects, while \c lupdate works with source
601
files and JSON description files and is build-system agnostic.
602
603
Use \c lupdate-pro when you have a qmake project and want to extract
604
translations based on the project structure defined in your .pro file.
605
606
\section1 lupdate-pro syntax
607
608
\badcode
609
lupdate-pro [options] [project-file]... [-ts ts-files...]
610
\endcode
611
612
Where:
613
614
\list
615
\li \c options means one or several \l {lupdate-pro options}.
616
\li \c project-file is a .pro file to process.
617
\li \c ts-files are the TS files to generate or update.
618
\endlist
619
620
To view the latest help, enter:
621
622
\badcode
623
lupdate-pro -help
624
\endcode
625
626
\section2 lupdate-pro options
627
628
\table
629
\header
630
\li Option
631
\li Action
632
\row
633
\li \c {-help}
634
\li Display up-to-date help information and exit.
635
\row
636
\li \c {-dump-json <file>}
637
\li Generate a JSON project description file without processing
638
translations. This file can be passed to \c lupdate or \c lrelease
639
using the \c {-project} option.
640
\row
641
\li \c {-silent}
642
\li Do not explain what is being done.
643
\row
644
\li \c {-pro <filename>}
645
\li Name of a .pro file. Useful for files with .pro file syntax but
646
different file suffix. Projects are recursed into and merged.
647
\row
648
\li \c {-pro-out <directory>}
649
\li Virtual output directory for processing subsequent .pro files.
650
\row
651
\li \c {-pro-debug}
652
\li Trace processing .pro files. Specify twice for more verbosity.
653
\row
654
\li \c {-ts <ts-file>...}
655
\li Specify the output TS files. This overrides \c TRANSLATIONS.
656
\row
657
\li \c {-no-obsolete}
658
\li Drop all obsolete and vanished strings.
659
\row
660
\li \c {-pluralonly}
661
\li Only include plural form messages.
662
\row
663
\li \c {-no-sort}
664
\li Do not sort contexts in TS files.
665
\row
666
\li \c {-locations {absolute|relative|none}}
667
\li Specify or override the way to save source code references in TS
668
files.
669
\row
670
\li \c {-no-ui-lines}
671
\li Do not record line numbers in references to UI files.
672
\row
673
\li \c {-source-language <language>[_<region>]}
674
\li Specify the language of the source strings for new files.
675
\row
676
\li \c {-target-language <language>[_<region>]}
677
\li Specify the language of the translations for new files.
678
\row
679
\li \c {-tr-function-alias <function>{+=,=}<alias>}
680
\li Recognize \c <alias> as an alternative spelling of \c <function>.
681
\row
682
\li \c {-version}
683
\li Display the version of \c lupdate-pro and exit.
684
\endtable
685
686
\section1 Examples
687
688
\section2 Update translations from a qmake project
689
690
\badcode
691
lupdate-pro myproject.pro
692
\endcode
693
694
\section2 Generate JSON project description
695
696
Generate a JSON file describing the project structure for use with
697
\c lupdate or \c lrelease:
698
699
\badcode
700
lupdate-pro myproject.pro -dump-json project.json
701
\endcode
702
703
Then use the generated JSON file with \c lupdate:
704
705
\badcode
706
lupdate -project project.json
707
\endcode
708
709
This two-step workflow is useful when you need to customize the project
710
description or integrate with other tools.
711
*/
712
713
/*!
714
\page linguist-lrelease-pro.html
715
\target lrelease-pro
716
717
\previouspage Using lupdate-pro
718
\nextpage Using lconvert
719
720
\title Using lrelease-pro
721
722
The \c lrelease-pro command line tool generates QM files from qmake
723
projects (.pro files). It reads the \c TRANSLATIONS variable from the
724
project file and generates the corresponding QM files.
725
726
Use \c lrelease-pro when you have a qmake project and want to generate
727
QM files based on the translations defined in your .pro file.
728
729
\section1 lrelease-pro syntax
730
731
\badcode
732
lrelease-pro [options] [project-file]...
733
\endcode
734
735
Where:
736
737
\list
738
\li \c options means one or several \l {lrelease-pro options}.
739
\li \c project-file is a .pro file to process.
740
\endlist
741
742
To view the latest help, enter:
743
744
\badcode
745
lrelease-pro -help
746
\endcode
747
748
\section2 lrelease-pro options
749
750
\table
751
\header
752
\li Option
753
\li Action
754
\row
755
\li \c {-help}
756
\li Display up-to-date help information and exit.
757
\row
758
\li \c {-dump-json <file>}
759
\li Generate a JSON project description file without generating
760
QM files. This file can be passed to \c lrelease using the
761
\c {-project} option.
762
\row
763
\li \c {-silent}
764
\li Do not explain what is being done.
765
\row
766
\li \c {-removeidentical}
767
\li If the translated text is the same as the source text, exclude the
768
message.
769
\row
770
\li \c {-fail-on-unfinished}
771
\li Generate an error if unfinished translations are found.
772
\row
773
\li \c {-fail-on-invalid}
774
\li Fail if translations failing the following checks are found:
775
\list
776
\li validity check of accelerators
777
\li validity check of surrounding whitespaces
778
\li validity check of ending punctuation
779
\li validity check of place markers
780
\endlist
781
To get more details refer to Qt Linguist help
782
\row
783
\li \c {-nounfinished}
784
\li Do not include unfinished translations.
785
\row
786
\li \c {-markuntranslated <prefix>}
787
\li If a message has no real translation, use the source text
788
prefixed with the given string instead.
789
\row
790
\li \c {-version}
791
\li Display the version of \c lrelease-pro and exit.
792
\endtable
793
794
\section1 Examples
795
796
\section2 Generate QM files from a qmake project
797
798
\badcode
799
lrelease-pro myproject.pro
800
\endcode
801
802
\section2 Generate JSON project description
803
804
Generate a JSON file describing the project's translations:
805
806
\badcode
807
lrelease-pro myproject.pro -dump-json project.json
808
\endcode
809
810
Then use the generated JSON file with \c lrelease:
811
812
\badcode
813
lrelease -project project.json
814
\endcode
815
*/
816
817
/*!
818
\page linguist-lconvert.html
819
\target lconvert
820
821
\previouspage Using lrelease-pro
822
\nextpage Using lcheck
823
824
\title Using lconvert
825
826
The \c lconvert command line tool filters and converts translation data
827
files.
828
829
It supports the following file formats:
830
\list
831
\li \c pot - GNU Gettext localization template files
832
\li \c qph - Qt Linguist Phrase Book
833
\li \c ts - Qt translation sources
834
\li \c po - GNU Gettext localization files
835
\li \c qm - Compiled Qt translations
836
\li \c xlf - XLIFF localization files
837
\endlist
838
839
\section1 lconvert syntax
840
841
\badcode
842
lconvert [options] <infile> [<infile>...]
843
\endcode
844
845
Where:
846
847
\list
848
\li \c options means one or several \l {lconvert options}.
849
\li \c infile is an input file. You can specify multiple input files.
850
\endlist
851
852
If you specify multiple input files, they are merged with translations from
853
later files taking precedence.
854
855
To view the latest \c lconvert help, enter:
856
857
\badcode
858
lconvert -help
859
\endcode
860
861
\section2 lconvert options
862
863
\table
864
\header
865
\li Option
866
\li Action
867
\row
868
\li \c -h \br \c -help
869
\li Display up-to-date help information and exit.
870
\row
871
\li \c {-i <infile>} \br \c {-input-file <infile>}
872
\li Specify an input file. Use this option if \c{<infile>} starts with a dash.
873
Use this option several times to merge inputs.
874
May be \c {-} (standard input) for use in a pipe.
875
\row
876
\li \c {-o <outfile>} \br \c {-output-file <outfile>}
877
\li Specify an output file. Default is \c {-} (standard output).
878
\row
879
\li \c {-if <informat>} \br \c {-input-format <format>}
880
\li Specify input format for subsequent input files.
881
The format is auto-detected from the file name and defaults to \c ts.
882
\row
883
\li \c {-of <outformat>} \br \c {-output-format <outformat>}
884
\li Specify output format. See \c -if.
885
\row
886
\li \c {-drop-tags <regexp>}
887
\li Drop named extra tags when writing \c TS or \c XLIFF files.
888
You can specify this option repeatedly.
889
\row
890
\li \c {-drop-translations}
891
\li Drop existing translations and reset the status to \c unfinished.
892
That implies \c {--no-obsolete}.
893
\row
894
\li \c {-source-language <language>[_<region>]}
895
\li Specify/override the language of the source strings. Defaults to
896
POSIX if not specified and the file does not name it yet.
897
\row
898
\li \c {-target-language <language>[_<region>]}
899
\li Specify or override the language of the translation.
900
By default, the target language is read from the file content or
901
guessed from the file name.
902
\row
903
\li \c {-no-obsolete}
904
\li Drop obsolete messages.
905
\row
906
\li \c {-no-finished}
907
\li Drop finished messages.
908
\row
909
\li \c {-no-untranslated}
910
\li Drop untranslated messages.
911
\row
912
\li \c {-sort-contexts}
913
\li Sort contexts in the output \c TS file alphabetically.
914
\row
915
\li \c {-sort-messages}
916
\li Sort messages in a context alphabetically in \c TS files.
917
\row
918
\li \c {-locations {absolute|relative|none}}
919
\li Override how source code references are saved in \c TS files.
920
Default is \c absolute.
921
\row
922
\li \c {-no-ui-lines}
923
\li Drop line numbers from references to \c UI files.
924
\row
925
\li \c {-pluralonly}
926
\li Drop non-plural form messages.
927
\row
928
\li \c {-verbose}
929
\li Explain what is being done.
930
\endtable
931
932
\section1 Examples
933
934
\section2 Convert TS file to XLIFF
935
936
To convert a single TS file to XLIFF, run the following command in the
937
terminal:
938
939
\badcode
940
lconvert -o myapp_de.xlf myapp_de.ts
941
\endcode
942
943
\section2 Merge multiple QM files
944
945
The following command merges multiple QM files into \c {full_de.qm}:
946
947
\badcode
948
lconvert -o full_de.qm qtbase_de.qm myapp_de.qm mylib_de.qm
949
\endcode
950
951
\section2 Using lconvert with CMake
952
953
To call \c lconvert when configuring or building your CMake project, load
954
the \c Qt6LinguistTools package and use \c
955
{$<TARGET_FILE_NAME:Qt6::lconvert>} for locating the \c lconvert executable.
956
957
The following example adds a custom target \c xlf_de that converts a single
958
TS file to XLIFF.
959
960
\badcode
961
find_package(Qt6 REQUIRED COMPONENTS LinguistTools)
962
963
add_custom_command(
964
OUTPUT myapp_de.xlf
965
COMMAND $<TARGET_FILE:Qt6::lconvert> -o myapp_de.xlf myapp_de.ts
966
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/myapp_de.ts"
967
VERBATIM
968
)
969
970
add_custom_target(xlf_de
971
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/myapp_de.xlf"
972
)
973
\endcode
974
975
\section1 PO format-specific options
976
977
When converting to PO format, you can disable automatic line wrapping
978
by setting the \c no-wrap flag in the \c po-flags extra metadata field.
979
By default, lines longer than 79 characters are wrapped. Set this field
980
in source code using the \l{Extra metadata (//~)}{//~ meta string}
981
(for example, \c{//~ po-flags no-wrap}) or directly in TS files using
982
the \c{<extra-po-flags>} element.
983
984
Other PO flags (see the
985
\l{https://www.gnu.org/software/gettext/manual/gettext.html#Sticky-flags-1}{GNU gettext documentation})
986
are preserved when converting between TS and PO formats but do not
987
affect \c lconvert processing.
988
989
\note The \c po-flags metadata is only preserved when converting directly
990
from TS to PO format.
991
*/
992
993
/*!
994
\page linguist-lcheck.html
995
\target lcheck
996
\previouspage Using lconvert
997
\nextpage Using ltext2id
998
999
\title Using lcheck
1000
1001
The \c lcheck command line tool validates Qt \c {TS} translation files and
1002
produces a human-readable report. It is part of the Qt Linguist toolchain
1003
and is intended for batch or CI usage to catch common localization issues
1004
early. By default, \c lcheck runs a set of checks and returns a non-zero
1005
exit code if at least one enabled check fails.
1006
1007
The default checks are:
1008
1009
\list
1010
\li \b Accelerator check — Verifies that the number of ampersands
1011
(mnemonics) in source and translation match.
1012
\li \b Surrounding whitespace check — Verifies that leading and trailing
1013
whitespace of source and translation match.
1014
\li \b Ending punctuation check — Verifies that source and translation
1015
end with the same punctuation.
1016
\li \b Place marker check — Verifies consistent usage of \c {%1}, \c {%2},
1017
and so on, between source and translation.
1018
\endlist
1019
1020
Each check can be disabled individually using command line options.
1021
1022
\section1 lcheck syntax
1023
1024
\badcode
1025
lcheck [options] -o report-output-file ts-file
1026
lcheck [options] ts-file
1027
\endcode
1028
1029
Where:
1030
1031
\list
1032
\li \c options means one or several \l {lcheck options}.
1033
\li \c ts-file is the \c {TS} file to validate.
1034
\li \c report-output-file is the path of the file to write the report to.
1035
If omitted, the report is written to the standard error stream.
1036
\endlist
1037
1038
To view the latest help, enter:
1039
1040
\badcode
1041
lcheck -help
1042
\endcode
1043
1044
\section2 lcheck options
1045
1046
\table
1047
\header
1048
\li Option
1049
\li Action
1050
\row
1051
\li \c {-help}
1052
\li Display up-to-date help information and exit.
1053
\row
1054
\li \c {-no-accelerator}
1055
\li Disable the accelerator (ampersand) consistency check.
1056
\row
1057
\li \c {-no-punctuation}
1058
\li Disable the ending punctuation consistency check.
1059
\row
1060
\li \c {-no-place-marker}
1061
\li Disable the check that ensures \c {%1}, \c {%2}, … are used
1062
consistently between source and translation.
1063
\row
1064
\li \c {-no-whitespaces}
1065
\li Disable the surrounding whitespace consistency check.
1066
\row
1067
\li \c {-check-finished}
1068
\li Also check messages marked as \e finished. By default, finished
1069
translations are not checked.
1070
\row
1071
\li \c {-o <outfile>}
1072
\li Write the validation report to \c <outfile>. If not specified, the
1073
report is written to standard error.
1074
\row
1075
\li \c {-version}
1076
\li Display the version of \c lcheck and exit.
1077
\endtable
1078
1079
\note The process exit status is non-zero if any enabled check fails. This
1080
makes \c lcheck suitable for use in CI pipelines.
1081
1082
\section1 Examples
1083
1084
\section2 Write a report to a file
1085
1086
\badcode
1087
lcheck -o lcheck_report.txt translations/myapp_de.ts
1088
\endcode
1089
1090
\section2 Disable selected checks
1091
1092
The following command runs all checks except accelerator and punctuation:
1093
1094
\badcode
1095
lcheck -no-accelerator -no-punctuation translations/myapp_de.ts
1096
\endcode
1097
1098
\section2 Check finished translations as well
1099
1100
\badcode
1101
lcheck -check-finished translations/myapp_de.ts
1102
\endcode
1103
1104
\section2 Use lcheck in a CI step
1105
1106
\badcode
1107
lcheck translations/myapp_de.ts && echo "Translations OK" || echo "Issues found"
1108
\endcode
1109
1110
\section2 Using lcheck with CMake
1111
1112
To call \c lcheck when configuring or building your CMake project, load
1113
the \c Qt6LinguistTools package and use \c {$<TARGET_FILE:Qt6::lcheck>}
1114
to locate the \c lcheck executable.
1115
1116
The following example adds a custom target \c check_translations that runs
1117
\c lcheck over a TS file and writes a report next to the build artifacts.
1118
1119
\badcode
1120
find_package(Qt6 REQUIRED COMPONENTS LinguistTools)
1121
1122
add_custom_command(
1123
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/lcheck_report.txt"
1124
COMMAND $<TARGET_FILE:Qt6::lcheck>
1125
-o "${CMAKE_CURRENT_BINARY_DIR}/lcheck_report.txt"
1126
"${CMAKE_CURRENT_SOURCE_DIR}/translations/myapp_de.ts"
1127
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/translations/myapp_de.ts"
1128
VERBATIM
1129
)
1130
1131
add_custom_target(check_translations
1132
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/lcheck_report.txt"
1133
)
1134
\endcode
1135
1136
\section2 Using lcheck with qmake
1137
1138
You can run \c lcheck directly on a TS file without specifying a project file:
1139
1140
\badcode
1141
lcheck translations/myapp_de.ts
1142
\endcode
1143
*/
1144
1145
/*!
1146
\page linguist-ltext2id.html
1147
\target ltext2id
1148
\previouspage Using lcheck
1149
\nextpage Translators
1150
1151
\title Using ltext2id
1152
1153
The \c ltext2id command line tool converts a project that uses
1154
text-based translations to use ID-based translations. It scans the
1155
project tree, updates source code to call the ID-based translation
1156
APIs, and adjusts the related \c {TS} files accordingly. In the case
1157
of any failed conversions, the source will be annotated with
1158
\c {//ltext2id error:} at the failed locations.
1159
1160
\note Make a full backup (or work on a clean Git branch) before
1161
running \c ltext2id. The tool modifies source files and \c {TS} files
1162
in place.
1163
1164
For best results, include both the sources and the \c {TS} files in
1165
the project root you pass to the tool so that updates stay consistent
1166
between code and translations.
1167
1168
\section1 ltext2id syntax
1169
1170
\badcode
1171
ltext2id [options] [project-root]
1172
\endcode
1173
1174
Where:
1175
1176
\list
1177
\li \c options means one or several \l {ltext2id options}.
1178
\li \c project-root is the directory to process recursively.
1179
\endlist
1180
1181
To view the latest help, enter:
1182
1183
\badcode
1184
ltext2id -help
1185
\endcode
1186
1187
\section2 ltext2id options
1188
1189
\table
1190
\header
1191
\li Option
1192
\li Action
1193
\row
1194
\li \c {-help}
1195
\li Display up-to-date help information and exit.
1196
\row
1197
\li \c {-no-labels}
1198
\li Do not generate labels for ID-based translations.
1199
By default, message contexts are used as labels so that
1200
entries keep a similar visualization in Qt Linguist.
1201
\row
1202
\li \c {-sort-messages}
1203
\li Sort messages in a context alphabetically in TS files.
1204
\row
1205
\li \c {-source-utf16}
1206
\li Treat source files as UTF-16 encoded (default: false).
1207
\row
1208
\li \c {-quiet}
1209
\li Suppress progress output.
1210
\row
1211
\li \c {-only-meta-id}
1212
\li Only suggest IDs by inserting meta strings; do \e not perform
1213
the actual transformation to ID-based calls.
1214
\row
1215
\li \c {-no-auto-id}
1216
\li Do not auto-generate IDs when meta-string IDs are missing.
1217
Translation function calls without meta IDs are ignored.
1218
\row
1219
\li \c {-version}
1220
\li Display the version of \c ltext2id and exit.
1221
\endtable
1222
1223
\section1 Examples
1224
1225
\section2 Convert a project to ID-based translations
1226
1227
Run the tool at the project root. The source code and \c {TS} files
1228
under that directory are updated in place.
1229
1230
\badcode
1231
ltext2id path/to/project
1232
\endcode
1233
1234
\section2 Generate only ID suggestions (no code changes)
1235
1236
Use \c -only-meta-id to inject meta-string ID suggestions without
1237
rewriting calls to the ID-based API. As a result, the translation
1238
calls are annotated by '//~ meta-id <id>' (cpp) meta string
1239
specifying the suggested IDs (meta ID).
1240
1241
\badcode
1242
ltext2id -only-meta-id path/to/project
1243
\endcode
1244
1245
\section2 Disable label generation
1246
1247
Prevent label generation if you do not want contexts mirrored as
1248
labels in Qt Linguist:
1249
1250
\badcode
1251
ltext2id -no-labels path/to/project
1252
\endcode
1253
1254
\section2 Avoid auto-generated IDs
1255
1256
Skip auto-generation for calls missing meta IDs, i.e., IDs
1257
already specified using the meta string '//~ meta-id <id>' (cpp):
1258
1259
\badcode
1260
ltext2id -no-auto-id path/to/project
1261
\endcode
1262
1263
\section2 Work with UTF-16 source files
1264
1265
If your sources are UTF-16 encoded, enable the option:
1266
1267
\badcode
1268
ltext2id -source-utf16 path/to/project
1269
\endcode
1270
1271
\section1 Exit status
1272
1273
\c ltext2id returns a non-zero exit code on failure (for example,
1274
when it encounters an unrecoverable error while transforming files).
1275
Inspect the in-place source annotations marked with
1276
\c {//ltext2id error:} to fix the remaining issues.
1277
*/
1278
1279
/*!
1280
\page linguist-translators.html
1281
1282
\previouspage Using ltext2id
1283
\nextpage Qt Linguist user interface
1284
1285
\title Translators
1286
1287
\image front-ui.png {UI illustration showing Start buttons, toggle,
1288
controls, and a circular selector on a dark screen}
1289
1290
\QL is a tool for translating strings in Qt applications. Once you have
1291
installed Qt, you can start \QL in the same way as any other application on
1292
the development host.
1293
1294
\note You can obtain an installer for \QL only (without the entire Qt SDK)
1295
from \l {https://download.qt.io/linguist_releases/}. The installer is
1296
available for Windows, and works with Qt 6.
1297
1298
To address issues that arise from the subtleties and complexities of
1299
human language, translators and developers may need to:
1300
1301
\list
1302
\li Translate a single phrase into several different forms depending on
1303
context. For example, \e open in English might become \e{\ouml}\e{ffnen},
1304
\e {open file}, or \e aufbauen, \e {open internet connection}, in German.
1305
1306
\li Change the mnemonic characters in keyboard shortcuts without introducing
1307
conflicts. For example, \c \&Quit in English becomes \e Avslutt in
1308
Norwegian, which does not contain the letter \e Q. You cannot use a
1309
letter that is already in use unless you change several shortcuts.
1310
1311
\li Rephrase strings that contain variables. For example, you might need to
1312
place the variables in a different order when you translate the string
1313
\e {The 25 files selected will take 63 seconds to process}, where the
1314
two numbers are inserted programmatically at runtime.
1315
\endlist
1316
1317
For more information about how to use \QL to translate applications, see:
1318
1319
\list
1320
\li \l {Qt Linguist user interface}
1321
\li \l {Translating strings}
1322
\li \l {Selecting context or label to translate}
1323
\li \l {Selecting strings to translate}
1324
\li \l {Viewing strings in context}
1325
\li \l {Reusing translations}
1326
\li \l {Validating translations}
1327
\li \l {Translating multiple languages simultaneously}
1328
\li \l {AI translation}
1329
\endlist
1330
*/
1331
1332
/*!
1333
\page linguist-ui.html
1334
1335
\previouspage Translators
1336
\nextpage Translating strings
1337
1338
\title Qt Linguist user interface
1339
1340
The \QL main window contains a menu bar and the following views:
1341
1342
\list
1343
1344
\li \uicontrol Context/Label (\key F6) lists translation contexts or labels.
1345
1346
\li \uicontrol Strings (\key F7) lists translatable strings in the
1347
selected context.
1348
1349
\li \uicontrol {Sources and Forms} (\key F9) displays the selected
1350
string in the source code.
1351
1352
\li Translation area displays the selected string and enables you to
1353
enter a translation for it.
1354
1355
\li \uicontrol {Phrases and guesses} (\key F10) lists possible
1356
translations for the current string.
1357
1358
\li \uicontrol Warnings (\key F8) lists translated strings that fail
1359
validation tests.
1360
1361
\endlist
1362
1363
\image linguist.webp {Qt Linguist UI}
1364
1365
The translation area (1) is always visible. To show or hide the other views,
1366
select \uicontrol View > \uicontrol Views, or use keyboard shortcuts.
1367
You can drag the views by their title bars and arrange them around the
1368
translation area or even outside the main window.
1369
*/
1370
1371
/*!
1372
\page linguist-translating-strings.html
1373
1374
\previouspage Qt Linguist user interface
1375
\nextpage Selecting context or label to translate
1376
1377
\title Translating strings
1378
1379
Open translation source (TS) files in \QL for translation. TS files are
1380
human-readable XML files containing source phrases and their translations.
1381
TS files are usually created and updated by \c lupdate. If you do not have
1382
a TS file, see \l {Creating translation files} to learn how to generate one.
1383
1384
You can use \QL also to translate files in the international XML
1385
Localization Interchange File Format (XLIFF) that are generated by other
1386
programs. However, for standard Qt projects, only the TS file format is
1387
used. Only XLIFF versions 1.1 and 1.2 are currently supported.
1388
1389
\QL displays the target language in the translation area, and adapts the
1390
number of input fields for plural forms accordingly. When you open several
1391
TS files to translate simultaneously, the \uicontrol Translator and
1392
\uicontrol {Translator comment} fields are displayed for each language.
1393
For more information about setting the location information, see
1394
\l{Changing the target locale}.
1395
1396
If the developer provides a disambiguating comment, you can see it in the
1397
\uicontrol {Developer comments} field.
1398
1399
To translate strings:
1400
\list 1
1401
1402
\li Select \uicontrol File > \uicontrol Open to load a TS file.
1403
1404
\li Select a context in the \uicontrol Context view to display translatable
1405
strings in the \uicontrol Strings view.
1406
1407
\image linguist-ui.webp {}
1408
1409
\li Select a string to display it in the \uicontrol {Source text} field
1410
in the translation area. The whitespace within the source text is
1411
visualized.
1412
1413
\li Enter the translation of the current string in the \uicontrol Translation
1414
field.
1415
1416
Double-click an existing translation in the
1417
\uicontrol {Phrases and guesses} field to use it as the translation
1418
for the current string. \QL reads the phrases from phrase books and
1419
bases the guesses on existing translations of similar phrases in the
1420
TS file.
1421
1422
\li Optionally, enter a comment for other translators in the
1423
\uicontrol {Translator comment} field.
1424
1425
\li To accept the translation, press \key {Ctrl+Enter}, select
1426
\inlineimage linguist-doneandnext.png {Icon}
1427
, or click the icon to the left of the selected source string in the
1428
string list.
1429
1430
\li Select \uicontrol File > \uicontrol Save to save your work.
1431
1432
\endlist
1433
1434
Repeat this process until all strings in the string list are marked with
1435
\inlineimage linguist-check-on.png {Check icon}
1436
(\uicontrol {Accepted/Correct}) or
1437
\inlineimage linguist-check-warning.png {Check warning icon}
1438
(\uicontrol {Accepted/Warnings}). Then select the next context and continue.
1439
1440
To view the number of words and characters in the source text and in the
1441
translated text, select \uicontrol View > \uicontrol Statistics.
1442
1443
Select \uicontrol File > \uicontrol Release to create a QM
1444
file with the same base name as the current translation source file.
1445
The \c lrelease tool performs the same function on \e all of an
1446
application's translation source files.
1447
1448
To print the translation source and the translations, select \uicontrol File >
1449
\uicontrol Print.
1450
1451
To quit \QL, select \uicontrol File > \uicontrol Exit.
1452
1453
\section1 Moving between translatable strings
1454
1455
To move to the next unfinished translation, select
1456
\inlineimage nextunfinished.png {Icon}
1457
(\uicontrol {Next Unfinished}) or press \key{Ctrl+J}.
1458
1459
To move to the next source text, select \inlineimage next.png {next icon}
1460
, press \key{Ctrl+Shift+J}, or select \uicontrol Translation >
1461
\uicontrol Next.
1462
1463
\section1 Phrases that require multiple translations depending on context
1464
1465
The same phrase may occur in more than one context without conflict. When
1466
you reach another occurrence of a translated phrase, \QL provides
1467
the previous translation as a possible translation in the
1468
\uicontrol {Phrases and guesses} view.
1469
1470
If a phrase occurs more than once within a particular context, it appears
1471
only once in the \uicontrol Context view, and the translation is applied
1472
to every occurrence within the context. If the same phrase means different
1473
things within the same context, the developer must provide a comment for
1474
each occurrence of the phrase. The duplicate phrases appear in the
1475
\uicontrol Context view. The developer's comments appear in the translation
1476
area on a light blue background.
1477
1478
\section1 Changing keyboard shortcuts
1479
1480
A keyboard shortcut is a key combination that performs an action.
1481
1482
\section2 Alt key shortcuts
1483
1484
In menu item and button text, a \e mnemonic character (marked by underlining)
1485
indicates that pressing \key Alt or \key Ctrl with the underlined character
1486
performs the same action as clicking the menu item or pressing the button.
1487
1488
For example, applications often use \e F as the mnemonic character in the
1489
\uicontrol {File} menu, so you can either click the menu item or press
1490
\key {Alt+F} to open the menu. The mnemonic character in the translatable
1491
string is prefixed with an ampersand: \c {\&File}. The translation for the
1492
string should also have an ampersand in it, preferably in front of the same
1493
character.
1494
1495
You can determine the meaning of an \key Alt key shortcut from the phrase
1496
that contains the ampersand. You can use another mnemonic character if the
1497
translated phrase does not contain the current one or if it is used in
1498
the translation of some other shortcut in the context. Some key shortcuts,
1499
usually those on the menu bar, may apply in other contexts.
1500
1501
\section2 Ctrl key shortcuts
1502
1503
\key Ctrl key shortcuts can exist independently of any visual control.
1504
Typically, they invoke actions in menus that would require multiple
1505
keystrokes or mouse clicks or actions that do not appear in any menu
1506
or on any button. For example, the \uicontrol {File} menu might contain a
1507
\uicontrol {\underline{N}ew Ctrl+N} item that you can invoke by pressing
1508
\key {Ctrl+N} even when the \uicontrol {File} menu is closed.
1509
1510
Each \key Ctrl key shortcut appears in the \uicontrol Strings view
1511
as a separate string. For example, \key{Ctrl+Enter}. Since
1512
the string does not have a context to give it meaning, such as
1513
the context of the phrase in which an \key Alt key shortcut appears,
1514
you must rely on the developer to include a \l{QObject::tr()}
1515
{disambiguation comment} to explain the action the \key Ctrl key
1516
shortcut performs. The comment appears under \uicontrol {Developer comments}
1517
in the translation area below the \uicontrol {Source text} field.
1518
1519
Ideally, you can copy translations for \key Ctrl key shortcuts by
1520
selecting \uicontrol Translation > \uicontrol {Copy from source text}.
1521
However, if the character does not make sense in the target language,
1522
change it. Whichever character (alpha or digit) you choose, use the form
1523
\key {Ctrl+} followed by the upper case character. Qt automatically displays
1524
the correct name at runtime. As with \key Alt key shortcuts, if you change
1525
the character, make sure that it does not conflict with any other
1526
\key Ctrl key shortcut.
1527
1528
\note Do not translate the \key Alt, \key Ctrl or \key Shift parts of
1529
the shortcuts, as Qt recognizes them and automatically translates them
1530
for supported languages.
1531
1532
\section1 Handling numbered arguments and plural forms
1533
1534
A numbered argument is a placeholder that will be replaced with text at
1535
runtime. It appears in a source string as a percent sign followed by
1536
a digit. For example, in the \c{After processing file %1, file %2
1537
is next in line} string, \c{%1} and \c{%2} are numbered arguments that
1538
are replaced with the first and second file names at runtime. The
1539
same numbered arguments must appear in the translation, but not
1540
necessarily in the same order. A German translation of the string
1541
might reverse the phrases, for example \c{Datei %2 wird bearbeitet, wenn
1542
Datei %1 fertig ist}. Both numbered arguments appear in the
1543
translation, but in the reverse order. A numbered argument is always
1544
replaced by the same text in the translations, regardless of the position
1545
in the argument sequence in the source string.
1546
1547
The use of numbered arguments is often accompanied by the use of
1548
plural forms in the source text. In many languages, the form of the
1549
text will depend on the value shown, and more than one translation
1550
is required. If the developers have marked up the source text in
1551
correct way, fields for each of the possible plural forms will be
1552
available in the translation area. For more information, see
1553
\l{Writing Source Code for Translation}.
1554
1555
\section1 Handling numeric character references (NCR) in translations
1556
1557
Select \uicontrol {NCR mode} to toggle the representation of
1558
numeric character references in both the source text and the translation
1559
fields. When selected, special characters in the text are displayed as their
1560
corresponding NCRs (for examlple,   for a non-breaking space). Otherwise, the
1561
characters appear in their standard visual form. This feature is useful
1562
for instance to maintain the same special characters (such as
1563
emojis, special spaces) in both the source text and its translations.
1564
1565
\section1 Changing the target locale
1566
1567
You can set the locale information explicitly in \uicontrol Edit >
1568
\uicontrol {Translation File Settings}. If the target language and country
1569
are not explicitly set when you open a translation source file, \QL
1570
attempts to deduct them from the translation source file name. This
1571
requires that the translation files adhere to the following file name
1572
convention:
1573
\c appname_language[_country].ts, where:
1574
1575
\list
1576
\li \c language is an ISO 639 language code in lowercase.
1577
\li \c country is an ISO 3166 two-letter country code in uppercase.
1578
\endlist
1579
1580
If this attempt to resolve the target language and country fails, the
1581
\uicontrol {Translation File Settings} window opens.
1582
1583
For example, \c app_de.ts sets the
1584
target language to German, and \c app_de_CH.ts sets the target language to
1585
German and the target country to Switzerland. This also helps loading
1586
translations for the current locale automatically. For more information, see
1587
\l{Enable Translation}.
1588
1589
\image linguist-translationfilesettings.png {Screenshot showing Qt Linguist
1590
settings window with source language POSIX and target language German}
1591
*/
1592
1593
/*!
1594
\page linguist-selecting-context.html
1595
1596
\previouspage Translating strings
1597
\nextpage Selecting strings to translate
1598
1599
\title Selecting context or label to translate
1600
1601
The \uicontrol Context/Label view lists the contexts (\uicontrol {Text based}) or
1602
labels (\uicontrol {ID based}) in which strings to be translated
1603
appear. The text-based translations are grouped into contexts, while ID-based
1604
translations are grouped into labels (see \l{Grouping ID-Based Translations}).
1605
The \uicontrol Context/Label lists the \e groups (that is, context or labels)
1606
based on the selected tab:
1607
\list
1608
\li Upon switching to the \uicontrol{Text-Based} tab,
1609
\uicontrol Context lists the context names in
1610
alphabetical order. Each context is the name of a QML type or a subclass of
1611
QObject.
1612
\li Upon switching to the \uicontrol{ID-Based} tab,
1613
\uicontrol Label lists the label names in
1614
alphabetical order. More info on labels can be found in \l{Grouping ID-Based Translations}.
1615
\endlist
1616
1617
\image linguist-context-view.webp {Context/Label view}
1618
1619
The following icons indicate the current translation state for each group:
1620
1621
\table
1622
\header
1623
\li State
1624
\li Icon
1625
\li Description
1626
1627
\row
1628
\li Accepted/Correct
1629
\li \inlineimage linguist-check-on.png {Check icon}
1630
\li All strings in the group have been translated, and all the
1631
translations passed the \l{Validating Translations}{validation tests}.
1632
1633
\row
1634
\li Accepted/Warnings
1635
\li \inlineimage linguist-check-warning.png {Check warning icon}
1636
\li All strings in the group have been translated or marked as translated,
1637
but at least one translation failed the validation tests.
1638
In the \uicontrol Strings view, you can see which string failed the test.
1639
1640
\row
1641
\li Not Accepted
1642
\li \inlineimage linguist-check-off.png {check off icon}
1643
\li At least one string in the group has not been translated or is not
1644
marked as translated.
1645
1646
\row
1647
\li Obsolete
1648
\li \inlineimage linguist-check-obsolete.png {check obsolete icon}
1649
\li None of the translated strings appears in the group any more. This
1650
usually means the context or label no longer exists in the application.
1651
\endtable
1652
1653
The \uicontrol Items column displays the total number of translatable strings in
1654
the group and the number of translated strings, separated by a slash (/).
1655
If the numbers are equal, all the translatable strings in the group have
1656
translations.
1657
*/
1658
1659
/*!
1660
\page linguist-selecting-strings.html
1661
1662
\previouspage Selecting context or label to translate
1663
\nextpage Viewing strings in context
1664
1665
\title Selecting strings to translate
1666
1667
The \uicontrol Strings view lists all the translatable strings in the
1668
current group (that is, context or label) and their translation acceptance
1669
state. Select a string to view and edit it in the translation area.
1670
1671
\image linguist-strings-view.webp {Strings view}
1672
1673
Click the icon in front of a string to change its translation acceptance
1674
state. A tick mark, green or yellow, means the string has an accepted
1675
translation. A question mark means either that the translation does not
1676
exist or you have not accepted it.
1677
1678
The following icons indicate the current translation state for each string:
1679
1680
\target String Translation States
1681
1682
\table
1683
\header
1684
\li State
1685
\li Icon
1686
\li Description
1687
1688
\row
1689
\li Accepted/Correct
1690
\li \inlineimage linguist-check-on.png {Check icon}
1691
\li The source string has a translation (possibly empty). You accepted
1692
the translation, and it passes all the \l{Validating Translations}
1693
{validation tests}. Click the icon to revoke acceptance of the
1694
translation. The state becomes \uicontrol {Not Accepted} if the string
1695
has a translation or \uicontrol {No Translation} if the translation is
1696
empty. If \c{lupdate} changes the contents of a string, its acceptance
1697
state becomes \uicontrol {Not Accepted}.
1698
1699
\row
1700
\li Accepted/Warnings
1701
\li \inlineimage linguist-check-warning.png {Check warning icon}
1702
\li You accepted the translation, but it does not pass all the validation
1703
tests. The \uicontrol Warnings view shows where it failed. If you click
1704
the icon to revoke acceptance of the translation, the state becomes
1705
\uicontrol {Validation Failures}.
1706
1707
\row
1708
\li Not Accepted
1709
\li \inlineimage linguist-check-off.png {check off icon}
1710
\li The string has a translation that passes all the validation tests, but
1711
you have not yet accepted the translation. Click the icon or press
1712
\key{Ctrl+Enter} to accept the translation. The state becomes
1713
\uicontrol {Accepted/Correct}.
1714
1715
\row
1716
\li No Translation
1717
\li \inlineimage linguist-check-empty.png {check empty icon}
1718
\li The string does not have a translation. If you click the icon to accept
1719
the empty translation, the state becomes \uicontrol {Accepted/Correct}.
1720
1721
\row
1722
\li Validation Failures
1723
\li \inlineimage linguist-danger.png {danger icon}
1724
\li The string has a translation, but the translation does not pass all the
1725
validation tests. The \uicontrol Warnings view shows the validation test
1726
failures. Click on the icon or press \key{Ctrl+Enter} to
1727
accept the translation even with validation failures. The state becomes
1728
\uicontrol {Accepted/Warnings}. Usually, you should fix the causes of the
1729
validation failures. The state will automatically become
1730
\uicontrol {Not Accepted} when you fix all failures.
1731
1732
\row
1733
\li Obsolete
1734
\li \inlineimage linguist-check-obsolete.png {check obsolete icon}
1735
\li The string is obsolete. It is no longer used in the context.
1736
See \l{Using lupdate} for instructions on how to remove obsolete
1737
messages from the file.
1738
1739
\endtable
1740
*/
1741
1742
/*!
1743
\page linguist-viewing-strings-in-context.html
1744
1745
\previouspage Selecting strings to translate
1746
\nextpage Reusing translations
1747
1748
\title Viewing strings in context
1749
1750
If \QL can access the source files containing the translatable strings, the
1751
\uicontrol {Sources and Forms} view shows the source context of the current
1752
string in the \uicontrol Strings view. It highlights the source code line
1753
that contains the current string. If \QL cannot find the source file, it
1754
shows the expected absolute file path.
1755
1756
If the source context shows the wrong source line, the translation file might
1757
be out of sync with the source files. For more information about how to sync
1758
the files, see \l{Using lupdate}.
1759
1760
\QD stores UI forms in special UI files (.ui). \QL attempts to show the
1761
translations in the forms.
1762
*/
1763
1764
/*!
1765
\page linguist-reusing-translations.html
1766
1767
\previouspage Viewing strings in context
1768
\nextpage Validating translations
1769
1770
\title Reusing translations
1771
1772
If the translated text is similar to the source text, select
1773
\uicontrol Translation > \uicontrol {Copy from source text}
1774
(or press \key{Ctrl+B}) to copy the source text into the
1775
translation area.
1776
1777
\e {Phrase books} provide a common set of translations
1778
to help ensure consistency. A phrase book is a set of source phrases, target
1779
(translated) phrases, and optional definitions. Typically, one phrase book
1780
is created per language and family of applications. Phrase books avoid
1781
duplication of effort since they contain translations for a family of
1782
applications.
1783
1784
The \uicontrol {Phrases and guesses} view displays the current string and its
1785
phrase book translations. If the current string is the same as or similar to
1786
a translated string, the view also lists the string and its translation.
1787
1788
To copy a translation from the \uicontrol {Phrases and guesses} view to the
1789
translation area, double-click it or select it and press \key Enter.
1790
1791
\section1 Batch translation
1792
1793
\image linguist-batchtranslation.png {Screenshot showing Qt Linguist batch
1794
translation window with options and phrase book selection}
1795
1796
Use the batch translation feature to automatically translate source
1797
texts that are also in a phrase book. To configure which phrase books to use
1798
in what order during the batch translation process, select \uicontrol Edit >
1799
\uicontrol {Batch Translation}. You can include only entries with no
1800
current translation and mark batch translated entries as \uicontrol Accepted.
1801
1802
\section1 Creating and editing phrase books
1803
1804
Phrase book files are human-readable XML files containing standard phrases
1805
and their translations. \QL creates and update the files. You can use them
1806
for any number of projects and applications.
1807
1808
To create a new phrase book, select \uicontrol Phrases > \uicontrol {New Phrase Book}.
1809
1810
\image linguist-phrasebookdialog.png {Screenshot of Qt Linguist phrase book editor
1811
showing source phrases with German translations}
1812
1813
To open a phrase book, select \uicontrol Phrases > \uicontrol {Open Phrase Book}, and
1814
then select the Qt phrase book file (.qph) to open.
1815
1816
To view and change open phrase books, select \uicontrol Phrases >
1817
\uicontrol {Edit Phrase Book}.
1818
1819
To add a new phrase, select \uicontrol {New Entry} (or press \key {Alt+N}) and
1820
type in a new source phrase, the translation, and an optional definition.
1821
This is useful to distinguish different translations of the same source
1822
phrase.
1823
1824
To add the translation you are working on to the current phrase book, select
1825
\uicontrol Phrases > \uicontrol {Add to Phrase Book} or press \key{Ctrl+T}. If multiple
1826
phrase books are loaded, you have to select one.
1827
1828
If you detect an error in a phrase book entry in the
1829
\uicontrol {Phrases and guesses} view, you can edit by right
1830
clicking it and selecting \uicontrol Edit. After fixing the
1831
error press \key{Enter} to leave the editing mode.
1832
1833
To delete a phrase, select it in the \uicontrol {Source phrase} list, and then
1834
select \uicontrol {Remove Entry}.
1835
1836
To print an open phrase book, select \uicontrol Phrases >
1837
\uicontrol {Print Phrase Book}.
1838
*/
1839
1840
/*!
1841
\page linguist-validating-translations.html
1842
1843
\previouspage Reusing translations
1844
\nextpage Translating multiple languages simultaneously
1845
1846
\title Validating translations
1847
1848
\QL provides the following validation tests for translations:
1849
1850
\list
1851
\li \e {Accelerator validation} detects translated phrases
1852
that do not have an ampersand when the source phrase does and vice
1853
versa.
1854
\li \e {Punctuation validation} detects differences in the
1855
terminating punctuation between source and translated phrases when
1856
this may be significant. For example, warns if the source phrase
1857
ends with an ellipsis, exclamation mark or question mark, and the
1858
translated phrase does not, and vice versa.
1859
\li \e {Phrases validation} detects source phrases that are
1860
also in the phrase book but whose translation differs from that
1861
in the phrase book.
1862
\li \e {Place marker validation} detects whether the same variables
1863
(like \c %1, \c %2) appear both in the source text and in the
1864
translation.
1865
\endlist
1866
1867
To switch validation tests on or off, select \uicontrol Validation or use the
1868
toolbar buttons.
1869
1870
Not accepted strings that fail validation tests are marked with the
1871
\uicontrol {Validation Failures} icon in the \uicontrol Strings view.
1872
Accepted strings are marked with \uicontrol {Accepted/Warnings}.
1873
1874
If you switch validation off and then switch it on later,
1875
\QL rechecks all phrases and marks any that fail validation.
1876
1877
The \uicontrol Warnings view lists the strings that fail the active
1878
validation tests. The first warning is also shown in the status bar
1879
at the bottom of the main window.
1880
1881
\note Only results of \e{active} validation tests are reported.
1882
*/
1883
1884
/*!
1885
\page linguist-translating-multiple-languages.html
1886
\target multiple languages
1887
1888
\previouspage Validating translations
1889
\nextpage AI translation
1890
1891
\title Translating multiple languages simultaneously
1892
1893
You can load and edit multiple translation files simultaneously.
1894
The following screen shot displays \e{German} and \e{French} translation
1895
files loaded.
1896
1897
\image linguist-linguist_2.webp {}
1898
1899
The translation area has color-coded text editing areas for both German and
1900
French. The \uicontrol Context/Label view and the \uicontrol Strings view have
1901
color-coded status columns for each language.
1902
1903
The \uicontrol Items column in the \uicontrol Context/Label view combines the values
1904
for both languages. If the number of translatable strings does not match the
1905
number of accepted strings, either or both languages have strings that you
1906
need to translate or accept. The \uicontrol Strings view shows the translation
1907
acceptance state of each string for each language.
1908
*/
1909
1910
/*!
1911
\page linguist-ai-translation.html
1912
\target ai translation
1913
1914
\previouspage Translating multiple languages simultaneously
1915
\nextpage Developers
1916
1917
\title AI translation
1918
1919
The AI Translation feature lets you automatically generate translations for the
1920
open TS file using large language models (LLMs). You can use either a local LLM
1921
server (such as \l{https://ollama.com}{Ollama},
1922
\l{https://lmstudio.ai}{LM Studio}, or
1923
\l{https://github.com/ggml-org/llama.cpp}{llama.cpp}) or cloud-based APIs that
1924
support the OpenAI-compatible REST protocol (such as OpenAI, Groq, or Anthropic).
1925
1926
Qt Linguist supports two API modes:
1927
\list
1928
\li \e{Ollama} - Ollama's native REST API. Use this when running
1929
\l{https://ollama.com}{Ollama} locally.
1930
\li \e{OpenAI Compatible} - The standard OpenAI REST API format. Use this for:
1931
\list
1932
\li Local servers: LM Studio, llama.cpp, or Ollama (which also supports
1933
OpenAI-compatible mode)
1934
\li Cloud providers: OpenAI, Groq, DeepSeek, and others
1935
\endlist
1936
\endlist
1937
1938
\section1 Setting up a local LLM server
1939
1940
To use AI Translation with a local server, install one of the following and
1941
download at least one model:
1942
1943
\list
1944
\li \l{https://ollama.com}{Ollama} - Easy to use, manages models automatically
1945
\li \l{https://lmstudio.ai}{LM Studio} - GUI application with model browser
1946
\li \l{https://github.com/ggml-org/llama.cpp}{llama.cpp} - Lightweight,
1947
runs GGUF models directly
1948
\endlist
1949
1950
\note Running LLMs locally requires sufficient memory depending on the model
1951
size and quantization level. Refer to your LLM server's documentation for
1952
specific requirements, for example
1953
\l{https://lmstudio.ai/docs/app/system-requirements}{LM Studio System Requirements}.
1954
1955
For Ollama, pull a model using the command line:
1956
1957
\code
1958
ollama pull qwen3:14b
1959
ollama serve
1960
\endcode
1961
1962
For LM Studio, download models through the application's interface and start
1963
the local server:
1964
1965
\code
1966
lms server start
1967
\endcode
1968
1969
For llama.cpp, you can either use one of the built-in model presets:
1970
1971
\code
1972
llama-server --fim-qwen-7b-default
1973
\endcode
1974
1975
Or download a GGUF model file and start the server manually:
1976
1977
\code
1978
llama-server -m model.gguf --port 8080
1979
\endcode
1980
1981
\section1 Using cloud APIs
1982
1983
To use cloud-based translation services, select \e{OpenAI Compatible} as the
1984
API type, enter the provider's API endpoint URL, and provide your API key.
1985
1986
Enter only the base URL without the \c{/v1} path suffix. For example, for
1987
\l{https://openrouter.ai}{OpenRouter} use \c{https://openrouter.ai/api}.
1988
Consult your provider's documentation for the correct endpoint URL.
1989
1990
\section1 Using the AI Translation dialog
1991
1992
In Linguist, choose \uicontrol{Tools > AI Translation} to open the
1993
AI Translation dialog:
1994
1995
The \c Configuration part of the dialog provides:
1996
1997
\list
1998
\li \uicontrol {API Type}: choose \e{Ollama} for local Ollama servers using
1999
Ollama's native API, or \e{OpenAI Compatible} for LM Studio, llama.cpp,
2000
cloud APIs, or Ollama in OpenAI-compatible mode.
2001
\li \uicontrol {Server URL}: the base URL where the server listens. Do not
2002
include the \c{/v1} path suffix.
2003
Default: \c http://localhost:11434 for Ollama,
2004
\c http://localhost:8080 for OpenAI Compatible.
2005
\li \uicontrol {API Key}: authentication key for cloud APIs (optional for
2006
local servers).
2007
\li \uicontrol Model: drop-down list of available models.
2008
\li \uicontrol Context: optional application context to improve translation
2009
accuracy (e.g., "medical software", "video game", "financial application").
2010
\endlist
2011
2012
\image translationDialog1.webp {Screenshot of Qt Linguist AI translation dialog - Configuration}
2013
2014
The \c Selection part of the dialog provides:
2015
\list
2016
\li \uicontrol File: the TS file to translate.
2017
\li \uicontrol Filter: limit translation to specific groups (contexts or labels).
2018
\li \uicontrol Translate: start the AI translation.
2019
\endlist
2020
2021
\image translationDialog2.webp {Screenshot of Qt Linguist AI translation dialog - Selection}
2022
2023
The \c Progress part of the dialog provides:
2024
\list
2025
\li A stop button to stop the translation progress
2026
\li \uicontrol {Apply Translations}: apply the translated items into the TS file.
2027
\endlist
2028
2029
\image translationDialog3.webp {Screenshot of Qt Linguist AI translation dialog - Progress}
2030
2031
During translation, progress messages appear in the \uicontrol{Translation Log}.
2032
When complete, review the translated texts in the log. Click
2033
\uicontrol{Apply Translations} to insert the AI-generated translations into
2034
the TS file.
2035
2036
\section1 Recommended models
2037
2038
The following models are recommended for translation tasks, balancing quality,
2039
speed, and resource usage. These models can be found on:
2040
2041
\list
2042
\li \l{https://ollama.com/library}{Ollama} - search by model name
2043
(e.g., \c{ollama pull qwen3:14b})
2044
\li \l{https://lmstudio.ai}{LM Studio} - search in the model browser
2045
\li \l{https://huggingface.co}{Hugging Face} - download GGUF files for llama.cpp
2046
\endlist
2047
2048
\table
2049
\header
2050
\li Model
2051
\li Size
2052
\li Notes
2053
\row
2054
\li Mistral Small 24B
2055
\li 14 GB
2056
\li High translation quality with strong multilingual support.
2057
Requires >16 GB VRAM for optimal performance.
2058
\row
2059
\li Qwen3 14B
2060
\li 9 GB
2061
\li Balance of quality and resource usage. Supports 100+ languages.
2062
\row
2063
\li Qwen3 30B
2064
\li 19 GB
2065
\li High-quality translations. Uses MoE architecture for efficient inference.
2066
\row
2067
\li Qwen2.5 14B
2068
\li 9 GB
2069
\li Strong multilingual support for 29+ languages including CJK languages.
2070
\row
2071
\li Gemma 3 12B
2072
\li 8 GB
2073
\li Supports 140+ languages. Good for resource-constrained systems.
2074
\row
2075
\li 7shi/llama-translate 8B
2076
\li 5 GB
2077
\li Specialized translation model for English, French, Chinese, and Japanese.
2078
Lightweight option for limited hardware. Available on Ollama only.
2079
\endtable
2080
2081
For systems with limited resources, smaller variants like Qwen3 8B (5 GB) or
2082
Qwen2.5 7B (5 GB) provide reasonable translation quality while requiring
2083
less memory.
2084
2085
\note Translation quality varies by language pair and model. Test different
2086
models to find the best combination of speed, quality, and resource usage for
2087
your specific translation needs.
2088
*/
2089
2090
/*!
2091
\page linguist-programmers.html
2092
\title Developers
2093
2094
\previouspage AI translation
2095
\nextpage TS File Format
2096
2097
\image front-coding.png {Illustration showing a code}
2098
2099
Design your application so that it can be adapted to various languages and
2100
regions without engineering changes.
2101
2102
\list
2103
\li \l{TS file format}
2104
\li \l{Text ID based translations}
2105
\li \l{Meta strings reference}
2106
\li \l{CMake Commands in Qt6 LinguistTools}{CMake commands}
2107
\li \l{Examples}
2108
\endlist
2109
2110
For more information, see also:
2111
\list
2112
\li \l {Internationalization with Qt}
2113
\li \l {Writing Source Code for Translation}
2114
\li \l {Localizing Applications}.
2115
\endlist
2116
2117
You can use Qt Creator wizard templates to create Qt widget-based projects
2118
with translation support. For more information, see
2119
\l {Qt Creator: Creating Projects}.
2120
2121
The following video shows how to internationalize and localize a simple
2122
example application:
2123
2124
\youtube xNIz78IPBu0
2125
*/
2126
2127
/*!
2128
\page linguist-programmers-examples.html
2129
\title Examples
2130
2131
\nextpage Developers
2132
2133
The following examples illustrate how to prepare Qt applications for
2134
translation:
2135
2136
\list
2137
\li \l{arrowpad}{Arrow Pad} is a C++ application that demonstrates how to
2138
make the application load translations depending on the current locale.
2139
It also shows the use of the two-argument form of \c tr() which provides
2140
additional information to the translator.
2141
2142
\li \l{trollprint}{Troll Print} is a C++ application that demonstrates how
2143
to distinguish identical source text in the same context. It also shows
2144
how minimize the translator's work when an application is upgraded.
2145
\endlist
2146
*/
2147
2148
/*!
2149
\page linguist-ts-file-format.html
2150
\title TS file format
2151
2152
\previouspage Developers
2153
2154
\brief TS file format.
2155
2156
The TS file format used by \QL is described by the
2157
\l{http://www.w3.org/2001/XMLSchema}{XSD} presented below,
2158
which we include for your convenience. Be aware that the format
2159
may change in future Qt releases.
2160
2161
\quotefile ../../../shared/ts.xsd
2162
2163
*/
2164
2165
/*!
2166
\page linguist-id-based-i18n.html
2167
\title Text ID based translations
2168
\ingroup internationalization
2169
2170
2171
\brief Text ID based internationalization provides support for large scale
2172
projects with many target locales and many texts to translate.
2173
2174
The text ID translation mechanism is an \e {industrial strength} system for
2175
internationalization and localization. Each text in the application has a
2176
unique identifier (text ID) that you use in the source code instead of text.
2177
This makes it much easier to manage large numbers of translated texts.
2178
2179
\section1 Internationalizing with text IDs
2180
2181
When using text IDs instead of plain text, the general method of
2182
internationalizing an application is the same but the details are a bit
2183
different:
2184
2185
\list 1
2186
2187
\li The functions and macros for the text-ID-based translation system are
2188
different from the plain-text system. You use the qsTrId() function instead
2189
of qsTr(), the QT_TRID_NOOP() macro instead of QT_TR_NOOP(),
2190
and QT_TRID_N_NOOP() macro instead of QT_TR_N_NOOP()).
2191
2192
\li Use text IDs as user interface strings rather than plain text
2193
strings. For example, \c {qsTrId("id-back-not-front")}
2194
2195
\li You cannot specify a context parameter with a text ID, and therefore
2196
identically spelled words with different meanings need separate
2197
text IDs. For example, \c {qsTrId("id-back-backstep")} differentiates
2198
the back-step \e {Back} from the \c id-back-not-front \e {Back}.
2199
2200
\li Since context names are not allowed for text-ID-based translations,
2201
\QL lists the IDs in a file without context names.
2202
2203
\li The \e {engineering English} text that you see in the user interface for
2204
development builds is indicated with a \c {//%} comment. If you do not
2205
include this, the text ID is shown in the user interface. This is
2206
especially important when you have texts with parameters. The \c {//%}
2207
comment needs to include the parameters indicators in the string. For
2208
example, \c {//% "Number of files: %1"}
2209
2210
\li The \c {//:} comments that provide extra information to the translator
2211
are optional in the plain-text system. However, with the text-ID-based
2212
system, this extra information becomes essential because without it you only
2213
have the text ID and the translator might not be able to make a sensible
2214
translation from that without further context. You can use long descriptive
2215
text IDs and no comments, but comments are often easier to understand.
2216
2217
\endlist
2218
2219
The side-by-side code snippets below show a comparison of text-ID -based and
2220
plain-text-based translations:
2221
2222
\table
2223
\header
2224
\li text-ID-based
2225
\li plain-text-based
2226
\row
2227
\li
2228
\code
2229
Text {
2230
id: backTxt;
2231
//: The back of the object, not the front
2232
//% "Back"
2233
//~ Context Not related to back-stepping
2234
text: qsTrId("id-back-not-front");
2235
}
2236
\endcode
2237
2238
\li
2239
\code
2240
Text {
2241
id: backTxt;
2242
//: The back of the object, not the front
2243
//~ Context Not related to back-stepping
2244
text: qsTr("Back","Not front")
2245
}
2246
\endcode
2247
\endtable
2248
2249
\section1 Localizing with text IDs
2250
2251
Localizing with text IDs follows much the same process as for plain text.
2252
2253
You use the \l{Using lupdate}{lupdate} tool to generate the TS files where
2254
you add the translations. The source values in the translation files will be
2255
text IDs rather than plain text, and therefore you need either descriptive
2256
text IDs or good additional comments, or both to ensure that the translations
2257
are accurate.
2258
2259
The example text-ID-based user interface text from above results in the following
2260
content in the .ts file:
2261
2262
\code
2263
<message id="id-back-not-front">
2264
<source>Back</source>
2265
<extracomment>The back of the object, not the front</extracomment>
2266
<translation type="unfinished"></translation>
2267
<extra-Context>Not related to back-stepping</extra-Context>
2268
</message>
2269
\endcode
2270
2271
If there is no translation available for a given text (which is
2272
generally the case until late in development), the text ID will be shown in
2273
the user interface rather than a proper text. In order to make the application
2274
more usable for testing, you can make \c lrelease use the \e {Engineering English}
2275
source text (from the \c {//%} comments) as the translated text and mark it with
2276
some indicator, such as an exclamation mark (!), so you can see texts that
2277
are not yet translated.
2278
2279
\section2 Grouping ID-Based Translations
2280
2281
You can assign each ID-based translation a \e label to organize
2282
ID-based entries of large projects into smaller groups.
2283
To assign a \e label to an ID-based entry, add a \c{//@} comment
2284
naming the label, for example in C++:
2285
\code cpp
2286
//% "Open file"
2287
//@ FileOperations
2288
qtTrId("msg.open");
2289
\endcode
2290
Or in QML:
2291
\code qml
2292
//% "Open file"
2293
//@ FileOperations
2294
qsTrId("msg.open");
2295
\endcode
2296
When you open the TS file in \l {Qt Linguist}, the ID-based entries with
2297
the same \e label are grouped together, similar to text-based
2298
entries that are grouped by context.
2299
Any item without a \e label appears under \c{<unnamed label>}.
2300
\note Label names have no effect on lookup or uniqueness: IDs remain globally
2301
unique and can still be loaded via \c{qtTrId("msgid")} without referencing a
2302
label. The label tag is used only to improve the translator's navigation
2303
and does not change runtime behavior.
2304
2305
\section3 Automatic Label Generation
2306
2307
Instead of manually specifying label names, you can use placeholders
2308
to automatically generate labels based on the code structure:
2309
2310
\list
2311
\li \c{//@ <context>} - Automatically uses the full context (namespace::class)
2312
\li \c{//@ <class>} - Automatically uses only the class name (without namespaces)
2313
\li \c{//@ <file>} - Automatically uses the source filename
2314
\endlist
2315
2316
\section4 Combining Placeholders
2317
2318
Placeholders can be combined with custom text to create more descriptive labels:
2319
2320
\list
2321
\li \c{//@ <file>:<class>} - Combines filename and class: \c{filehandler.cpp:FileHandler}
2322
\li \c{//@ <context>_customSuffix} - Adds suffix: \c{MyApp::FileHandler_customSuffix}
2323
\li \c{//@ module_<file>_<class>-label} - Custom prefix and suffix: \c{module_filehandler.cpp_FileHandler-label}
2324
\li \c{//@ <context>:<file>} - Context with file: \c{MyApp::FileHandler:filehandler.cpp}
2325
\endlist
2326
2327
For example, in C++:
2328
\code cpp
2329
namespace MyApp {
2330
class FileHandler : QObject {
2331
Q_OBJECT
2332
void open() {
2333
//% "Open file"
2334
//@ <context>
2335
qtTrId("msg.open"); // Label: MyApp::FileHandler
2336
2337
//% "Save file"
2338
//@ <class>
2339
qtTrId("msg.save"); // Label: FileHandler
2340
2341
//% "Export"
2342
//@ <file>
2343
qtTrId("msg.export"); // Label: filehandler.cpp
2344
}
2345
};
2346
}
2347
\endcode
2348
2349
Or in QML:
2350
\code qml
2351
Item {
2352
id: myComponent
2353
Component.onCompleted: {
2354
//% "Loading"
2355
//@ <context>
2356
qsTrId("msg.loading") // Label: <component-name>
2357
2358
//% "Ready"
2359
//@ <file>
2360
qsTrId("msg.ready") // Label: main.qml
2361
2362
//% "Initialized"
2363
//@ <file>:<context>-state
2364
qsTrId("msg.init") // Label: main.qml:<component-name>-state
2365
}
2366
}
2367
\endcode
2368
2369
Auto labels are particularly useful in large projects where manually
2370
managing label names across many files can be tedious. They ensure
2371
consistent grouping based on code structure and give hints to translators
2372
about where the translation will be used.
2373
2374
\note When using \c{<class>} in C++ code outside any classes, a warning
2375
will be issued and \c{<unnamed>} will be used in the generated label.
2376
2377
\note Using \c{<class>} in QML will generate a
2378
warning and \c{<unnamed>} will be used, since QML
2379
components are not classes. Use \c{<context>} instead to get the
2380
component name, or \c{<file>} to get the QML filename.
2381
2382
\note Auto labels only work with ID-based translations (\c qtTrId, \c qsTrId).
2383
Using auto labels with text-based translations (\c tr, \c qsTr) will generate
2384
a warning and the label will be ignored.
2385
2386
\section1 CMake configuration
2387
2388
When building with CMake, use the prefix \c qml_ for .ts files.
2389
For example, \c qml_en.ts. In the CMakeLists.txt file, add the
2390
\l qt_add_translations function, where you list the *.ts files
2391
as values of \c TS_FILES, and set the value of RESOURCE_PREFIX to the
2392
URI of the main.qml file for the project followed by /i18n:
2393
2394
\badcode
2395
qt_add_translations(${CMAKE_PROJECT_NAME}
2396
TS_FILES i18n/qml_de_DE.ts i18n/qml_en_US.ts
2397
RESOURCE_PREFIX Main/i18n
2398
)
2399
\endcode
2400
2401
\section1 Advanced use with qmake
2402
2403
For projects that target a large number of locales, you can remove the
2404
TRANSLATIONS info from the .pro file and, instead, manage the translations
2405
with a separate script. The script can call \c lrelease and \c lupdate for each of
2406
the desired targets.
2407
2408
The updates could be scripted something like this:
2409
2410
\code
2411
lupdate -recursive <project-dir> -ts <project-dir>/i18n/myapp-text_en_GB.ts
2412
lupdate -recursive <project-dir> -ts <project-dir>/i18n/myapp-text_en_US.ts
2413
...
2414
\endcode
2415
2416
The generation of the final .qm files could be scripted something like this:
2417
2418
\code
2419
lrelease <project-dir>/i18n/myapp-text_en_GB.ts
2420
lrelease <project-dir>/i18n/myapp-text_en_US.ts
2421
...
2422
\endcode
2423
2424
*/
2425
2426
/*!
2427
\page linguist-meta-strings-reference.html
2428
\title Meta strings reference
2429
\ingroup internationalization
2430
2431
\previouspage Text ID based translations
2432
2433
\brief Reference guide for meta strings used in Qt's translation system.
2434
2435
Meta strings are special comments that provide additional information to
2436
lupdate and \QL for translation processing. They use specific
2437
prefixes to identify their purpose and can be used in C++, QML, and Python code.
2438
2439
\section1 Meta string syntax overview
2440
2441
Meta strings are special comments that use specific prefixes to provide lupdate
2442
with additional information about translations:
2443
2444
\table
2445
\header
2446
\li Meta String
2447
\li Purpose
2448
\li Usage
2449
\row
2450
\li \c{//:}
2451
\li Extra comment for translators
2452
\li Provides context and guidance to help translators
2453
\row
2454
\li \c{//%}
2455
\li Source text (engineering English)
2456
\li Defines display text for ID-based translations during development
2457
\row
2458
\li \c{//@}
2459
\li Label for grouping
2460
\li Organizes ID-based translations into logical groups
2461
\row
2462
\li \c{//~}
2463
\li Extra key-value metadata
2464
\li Stores additional custom information about the translation
2465
\row
2466
\li \c{// TRANSLATOR}
2467
\li Magic comment for context
2468
\li Provides context information about the class or file
2469
\endtable
2470
2471
\note The \c{//=} meta string for message ID mapping is deprecated and should not be used in new code.
2472
2473
\section1 Translator comments (//:)
2474
2475
Use \c{//:} comments to provide additional context and guidance to translators.
2476
These comments appear in the \QL translation interface and help
2477
translators understand the meaning and usage of the text.
2478
2479
\section2 C++ example
2480
\code cpp
2481
//: Button to navigate backwards in the application
2482
tr("Back");
2483
2484
//: This is a file menu item that opens an existing document.
2485
//: Keep translation short to fit in menu.
2486
tr("Open");
2487
\endcode
2488
2489
\section2 QML example
2490
\code qml
2491
Button {
2492
//: Emergency stop button - must be clearly visible
2493
text: qsTr("STOP")
2494
}
2495
\endcode
2496
2497
\section2 Python example
2498
\code python
2499
#: Button to navigate backwards in the application
2500
self.tr("Back")
2501
2502
#: This is a file menu item that opens an existing document.
2503
#: Keep translation short to fit in menu.
2504
self.tr("Open")
2505
\endcode
2506
2507
Multiple translator comments can be used for the same string and will be
2508
concatenated with newlines in the TS file.
2509
2510
\section2 TS file format
2511
2512
Translator comments appear as \c{<extracomment>} elements in the TS file:
2513
2514
\code xml
2515
<message>
2516
<source>Back</source>
2517
<extracomment>Button to navigate backwards in the application</extracomment>
2518
<translation type="unfinished"></translation>
2519
</message>
2520
\endcode
2521
2522
\section1 Source text (//%)
2523
2524
The \c{//%} meta string defines the \e{engineering English} text that appears
2525
in the user interface during development when using ID-based translations.
2526
This is essential for making the application usable before translations
2527
are complete.
2528
2529
\section2 C++ example
2530
\code cpp
2531
//% "Save Document"
2532
qtTrId("file.save");
2533
2534
//% "Found %n items"
2535
qtTrId("search.results", count);
2536
\endcode
2537
2538
\section2 QML example
2539
\code qml
2540
Text {
2541
//% "Welcome to the application"
2542
text: qsTrId("welcome.message")
2543
}
2544
\endcode
2545
2546
\section2 Important notes
2547
\list
2548
\li Include parameter placeholders (%1, %n) in the source text
2549
\li The source text should be production-ready English
2550
\li Without //% comments, the text ID itself appears in the UI
2551
\endlist
2552
2553
\section2 TS file format
2554
2555
Source text appears as the \c{<source>} element:
2556
2557
\code xml
2558
<message id="file.save">
2559
<source>Save Document</source>
2560
<translation type="unfinished"></translation>
2561
</message>
2562
\endcode
2563
2564
\section1 Labels (//@)
2565
2566
Use \c{//@} meta strings to organize ID-based translations into logical
2567
groups or categories within \QL. This is particularly useful
2568
for large projects with many translation strings.
2569
2570
\note The \c{//@} meta string is only intended for ID-based translations
2571
(qtTrId/qsTrId) and should not be used with text-based translations (tr/qsTr).
2572
2573
\section2 C++ example
2574
\code cpp
2575
//% "New Document"
2576
//@ FileOperations
2577
qtTrId("file.new");
2578
2579
//% "Print Document"
2580
//@ FileOperations
2581
qtTrId("file.print");
2582
2583
//% "Connection failed"
2584
//@ NetworkErrors
2585
qtTrId("network.error.connection");
2586
\endcode
2587
2588
\section2 QML example
2589
\code qml
2590
Button {
2591
//% "Login"
2592
//@ Authentication
2593
text: qsTrId("auth.login")
2594
}
2595
\endcode
2596
2597
\note Labels are not applicable to Python translations since Python only supports
2598
text-based translations (self.tr()) and not ID-based translations.
2599
2600
Strings with the same label appear grouped together in \QL,
2601
making it easier for translators to work on related content.
2602
2603
For automatic label generation using placeholders like \c{<context>}, \c{<class>},
2604
\c{<file>}, and their combinations, see \l{Automatic Label Generation}.
2605
2606
\section2 TS file format
2607
2608
Labels appear as a \c{label} element:
2609
2610
\code xml
2611
<message id="file.new" label="FileOperations">
2612
<source>New Document</source>
2613
<label>FileOperations</label>
2614
<translation type="unfinished"></translation>
2615
</message>
2616
\endcode
2617
2618
\section1 Extra metadata (//~)
2619
2620
The \c{//~} meta string allows you to attach arbitrary key-value metadata
2621
to translations. This can be used for custom processing or translator
2622
guidance.
2623
2624
\section2 Syntax
2625
\code
2626
//~ key value
2627
//~ key "quoted value with spaces"
2628
\endcode
2629
2630
\section2 C++ example
2631
\code cpp
2632
//% "Error"
2633
//: Critical system error dialog
2634
//~ Severity High
2635
//~ MaxLength "20"
2636
//~ Context "Error dialogs"
2637
qtTrId("system.error");
2638
\endcode
2639
2640
\section2 QML example
2641
\code qml
2642
Text {
2643
//% "Loading..."
2644
//~ Context "Progress indicators"
2645
//~ ShowDuration "true"
2646
text: qsTrId("progress.loading")
2647
}
2648
\endcode
2649
2650
\section2 Python example
2651
\code python
2652
#~ Severity High
2653
#~ Context "Error dialogs"
2654
self.tr("Critical system error")
2655
\endcode
2656
2657
\section2 TS file format
2658
2659
Extra metadata appears as \c{<extra-*>} elements in the TS file and can be
2660
processed by custom tools or translation workflows.
2661
2662
\code xml
2663
<message id="system.error">
2664
<source>Error</source>
2665
<comment>Critical system error dialog</comment>
2666
<translation type="unfinished"></translation>
2667
<extra-Severity>High</extra-Severity>
2668
<extra-MaxLength>20</extra-MaxLength>
2669
<extra-Context>Error dialogs</extra-Context>
2670
</message>
2671
\endcode
2672
2673
\section2 Recognized extra keys
2674
2675
While any key can be used with \c{//~}, the \c no-wrap flag within
2676
\c po-flags is recognized by \c lconvert. See \l{PO format-specific options}.
2677
2678
\section1 TRANSLATOR magic comments
2679
2680
\c{TRANSLATOR} comments provide context information about a class or
2681
source file to help translators understand where translations are used.
2682
2683
\section2 C++ example
2684
\snippet doc_src_linguist-manual.cpp 5
2685
2686
\section2 QML example
2687
\code qml
2688
// TRANSLATOR LoginDialog Login dialog for user authentication
2689
Item {
2690
Text {
2691
text: qsTr("Username")
2692
}
2693
}
2694
\endcode
2695
2696
\section2 Python example
2697
\code python
2698
# TRANSLATOR MainWindow
2699
#
2700
# Main application window containing the primary user interface.
2701
# Keep button labels concise due to space constraints.
2702
#
2703
class MainWindow(QMainWindow):
2704
def setupUi(self):
2705
self.tr("File") # translations for this context
2706
\endcode
2707
2708
\section2 TS file format
2709
2710
TRANSLATOR comment appear as a \c{<message>} elements with empty source text
2711
on the \c{<context>} element:
2712
2713
\code xml
2714
<context>
2715
<name>Main</name>
2716
<message>
2717
<source></source>
2718
<comment>LoginDialog Login dialog for user authentication</comment>
2719
<translation></translation>
2720
</message>
2721
</context>
2722
\endcode
2723
2724
\section1 Combining meta strings
2725
2726
Meta strings can be combined to provide comprehensive translation metadata:
2727
2728
\section2 Complete C++ example
2729
\code cpp
2730
//: File dialog - confirm destructive action
2731
//: This will permanently delete the selected files
2732
//% "Delete Selected Files"
2733
//@ FileOperations
2734
//~ Severity High
2735
//~ RequiresConfirmation "true"
2736
qtTrId("file.delete.confirm");
2737
\endcode
2738
2739
\section2 Complete QML example
2740
\code qml
2741
Text {
2742
//: Shows current connection status to server
2743
//: Updates automatically every few seconds
2744
//% "Connected to server"
2745
//@ NetworkStatus
2746
//~ UpdateFrequency "5000ms"
2747
//~ Color "green"
2748
text: qsTrId("status.connected")
2749
}
2750
\endcode
2751
2752
\section1 Best practices
2753
2754
\list
2755
\li Use translator comments (//:) generously to provide context
2756
\li Always include source text (//%) for ID-based translations
2757
\li Group related translations using labels (//@) in large projects
2758
\li Place meta strings immediately before the translation function call
2759
\li Keep translator comments clear and concise but informative
2760
\li Use consistent naming for labels and extra metadata keys
2761
\endlist
2762
*/
qttools
src
linguist
linguist
doc
src
linguist-manual.qdoc
Generated on
for Qt by
1.16.1