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
25
\li \inlineimage front-ui.png
26
\li \inlineimage front-coding.png
27
\row
28
\li \l{Release managers}
29
\li \l{Translators}
30
\li \l{Developers}
31
\row
32
\li
33
\list
34
\li \l {Creating translation files}
35
\li \l {Using lupdate}
36
\li \l {Using lrelease}
37
\li \l {Using lconvert}
38
\li \l {Using lcheck}
39
\endlist
40
\li
41
\list
42
\li \l {Qt Linguist user interface}
43
\li \l {Translating strings}
44
\li \l {Selecting context or label to translate}
45
\li \l {Selecting strings to translate}
46
\li \l {Viewing strings in context}
47
\li \l {Reusing translations}
48
\li \l {Validating translations}
49
\li \l {Translating multiple languages simultaneously}
50
\endlist
51
\li
52
\list
53
\li \l{TS file format}
54
\li \l{Text ID based translations}
55
\li \l{Meta strings reference}
56
\li \l{CMake Commands in Qt6 LinguistTools}{CMake commands}
57
\li \l{Examples}
58
\endlist
59
\endtable
60
61
The following video shows how to internationalize and localize a simple
62
example application:
63
64
\youtube xNIz78IPBu0
65
*/
66
67
/*!
68
\page linguist-toc.html
69
\title All topics
70
71
\list
72
\li \l{Release managers}
73
\list
74
\li \l {Creating translation files}
75
\li \l {Using lupdate}
76
\li \l {Using lrelease}
77
\endlist
78
\li \l{Translators}
79
\list
80
\li \l {Qt Linguist user interface}
81
\li \l {Translating strings}
82
\li \l {Selecting context or label to translate}
83
\li \l {Selecting strings to translate}
84
\li \l {Viewing strings in context}
85
\li \l {Reusing translations}
86
\li \l {Validating translations}
87
\li \l {Translating multiple languages simultaneously}
88
\endlist
89
\li \l{Developers}
90
\list
91
\li \l{TS file format}
92
\li \l{Text ID based translations}
93
\li \l{Meta strings reference}
94
\li \l{CMake Commands in Qt6 LinguistTools}{CMake commands}
95
\li \l{Examples}
96
\endlist
97
\endlist
98
*/
99
100
/*!
101
\page linguist-manager.html
102
\title Release managers
103
104
\previouspage Qt Linguist Manual
105
\nextpage Creating translation files
106
107
\image front-publishing.png
108
109
Release managers use \c lupdate to generate a set of translation source (TS)
110
files from the application source files (QML and C++) and pass them to
111
translators. The translators use \QL to translate the strings and pass the
112
TS files back to the release managers. They use \c lrelease to generate
113
compact versions of the TS files, called Qt message (QM) files, that are
114
ready for use by the application.
115
116
\list
117
\li \l {Creating translation files}
118
\li \l {Using lupdate}
119
\li \l {Using lrelease}
120
\endlist
121
122
You can use the tools in repeated cycles as applications change and evolve.
123
They preserve existing translations and make it easy to identify new strings.
124
In addition, you can use the \QL phrase books to consistently translate
125
multiple applications and projects.
126
127
You can configure CMake projects to automatically run \c lupdate and
128
\c lrelease when you build a project and generate TS and QM files for you.
129
130
You can use the Qt Design Studio
131
\l{https://doc-snapshots.qt.io/qtdesignstudio/studio-translations.html}
132
{Translations} view to test and manage \l {Text ID based translations}
133
{ID-based translations}.
134
*/
135
136
/*!
137
\page linguist-creating-ts-files.html
138
139
\previouspage Release managers
140
\nextpage Using lupdate
141
142
\title Creating translation files
143
144
Most of the text to translate in an application consists of either single
145
words or short phrases. These typically appear as window titles, menu
146
items, tooltips, and labels to buttons, check boxes, and radio buttons.
147
148
Developers mark the phrases as translatable in the QML and C++ source code.
149
The Qt tools provide context information for each of the phrases to help the
150
translator understand their meaning. The developer can add comments to the
151
phrases.
152
153
Translation files consist of all the user-visible text and \key Ctrl key
154
shortcuts in an application and translations of that text.
155
156
To create translation files:
157
158
\list 1
159
160
\li Run \c lupdate to generate the first set of translation source (TS)
161
files with all the user-visible text but no translations.
162
163
\li Give the TS files to translators who add translations using \QL.
164
\QL indicates changed and deleted source text.
165
166
\li Run \c lupdate to incorporate any new text added to the application.
167
\c lupdate synchronizes the user-visible text from the application
168
with the translations. Existing translations in the TS file are
169
preserved.
170
171
\li Run \c lrelease to read the TS files and produce the QM files used
172
by the application at runtime.
173
174
\endlist
175
176
For \c lupdate to work successfully, it must know which translation files to
177
produce. Specify the files in the application's Qt project file.
178
179
When building with CMake, you use \l{CMake Commands in Qt6 LinguistTools}
180
{CMake commands} to add targets that create or update TS files and transform
181
them into QM files. The translation files are generated when you build the
182
targets.
183
*/
184
185
/*!
186
\page linguist-lupdate.html
187
\target lupdate
188
189
\previouspage Release managers
190
\nextpage Using lrelease
191
192
\title Using lupdate
193
194
The \c lupdate command line tool finds translatable strings in C++ source,
195
C++ header, Java, Python, QML, and UI files and generates or updates TS
196
files.
197
198
When building with qmake, specify the files to process at the command line
199
or in a .pro file.
200
201
When building with CMake, use \l{CMake Commands in Qt6 LinguistTools}
202
{CMake commands} to add targets that create or update TS files and transform
203
them into QM files. The \c lupdate tool is run with the \l {lupdate options}
204
{options} you pass to the commands when you build the target.
205
206
For more information about specifying translations in project files, see
207
\l{Localizing Applications}.
208
209
\section1 lupdate syntax
210
211
\badcode
212
lupdate [options] [project-file]...
213
lupdate [options] [source-file|path|@lst-file]... -ts ts-files|@lst-file
214
\endcode
215
216
Where:
217
218
\list
219
\li \c options means one or several \l {lupdate options}.
220
\li \c project-file is the project configuration file.
221
\li \c source-file is a file that contains translatable strings.
222
\li \c path is the path to a folder that contains translation
223
source files.
224
\li \c @lst-file reads additional file names (one per line) or
225
includepaths (one per line and prefixed with \c -I) from \e lst-file.
226
\li \c ts-files are the TS files to generate or update.
227
\endlist
228
229
To view the latest help, enter:
230
231
\badcode
232
lupdate -help
233
\endcode
234
235
\section2 lupdate options
236
237
\table
238
\header
239
\li Option
240
\li Action
241
\row
242
\li \c {-help}
243
\li Display up-to-date help information and exit.
244
\row
245
\li \c {-no-obsolete}
246
\li Drop all obsolete and vanished strings.
247
\row
248
\li \c {-extensions <ext>[,<ext>]...}
249
\li Process files with the given extensions, only. Use commas to
250
separate extensions in the list. Do not use whitespace. The default
251
value is:
252
\c {java,jui,ui,c,c++,cc,cpp,cxx,ch,h,h++,hh,hpp,hxx,js,qs,qml,qrc}.
253
\row
254
\li \c {-pluralonly}
255
\li Only include plural form messages.
256
\row
257
\li \c {-silent}
258
\li Do not explain what is being done.
259
\row
260
\li \c {-no-sort}
261
\li Do not sort contexts in TS files.
262
\row
263
\li \c {-sort-messages}
264
\li Sort messages in a context alphabetically in TS files.
265
\row
266
\li \c {-no-recursive}
267
\li Do not recursively scan directories.
268
\row
269
\li \c {-recursive}
270
\li Recursively scan directories (default).
271
\row
272
\li \c {-warnings-are-errors}
273
\li Treat warnings as errors.
274
\row
275
\li \c {-I <includepath> or -I<includepath>}
276
\li Look for include files in this additional location. You can specify
277
multiple paths.
278
\row
279
\li \c {-locations {absolute|relative|none}}
280
\li Specify or override the way to save source code references in TS
281
files.
282
\list
283
\li \c absolute means that the source file path is relative to
284
the target file, but the line number is absolute.
285
\li \c relative means that the source file path is relative to
286
the target file. The line number is relative to other
287
entries in the same source file.
288
\li \c none stores no information about source location.
289
\endlist
290
If you do not specify the location, \c lupdate determines it from
291
existing TS files. The default value for new files is \c absolute.
292
\row
293
\li \c {-no-ui-lines}
294
\li Do not record line numbers in references to UI files.
295
\row
296
\li \c {-disable-heuristic {sametext|similartext}}
297
\li Disable the named merge heuristic. Can be specified multiple times.
298
\row
299
\li \c {-project <filename>}
300
\li Name of a file containing the project's description in JSON format.
301
You can use the \c lprodump tool to generate the file from a .pro
302
file.
303
\row
304
\li \c {-pro <filename>}
305
\li Name of a .pro file. Useful for files with the .pro file syntax but
306
some other file suffix. Projects are recursed into and merged.
307
This option is deprecated. Use the \c lupdate-pro tool instead.
308
\row
309
\li \c {-pro-out <directory>}
310
\li Virtual output directory for processing subsequent .pro files.
311
\row
312
\li \c {-pro-debug}
313
\li Trace processing .pro files. Specify twice for more verbosity.
314
\row
315
\li \c {-source-language <language>[_<region>]}
316
\li Specify the language of the source strings for new files.
317
Defaults to POSIX if not specified.
318
\row
319
\li \c {-target-language <language>[_<region>]}
320
\li Specify the language of the translations for new files.
321
If you do not specify the language, \c lupdate determines it from
322
the file name.
323
\row
324
\li \c {-tr-function-alias <function>{+=,=}<alias>[,<function>{+=,=}<alias>]...}
325
\li With \c {+=}, recognize \c <alias> as an alternative spelling of
326
\c <function>.
327
With \c {=,} recognize \c <alias> as the only spelling of
328
\c <function>.
329
330
Available \c <function> values (with their currently defined aliases)
331
are:
332
\list
333
\li \c {Q_DECLARE_TR_FUNCTIONS} (\c {=Q_DECLARE_TR_FUNCTIONS})
334
\li \c {QT_TR_N_NOOP} (\c {=QT_TR_N_NOOP})
335
\li \c {QT_TRID_N_NOOP} (\c {=QT_TRID_N_NOOP})
336
\li \c {QT_TRANSLATE_N_NOOP} (\c {=QT_TRANSLATE_N_NOOP})
337
\li \c {QT_TRANSLATE_N_NOOP3} (\c {=QT_TRANSLATE_N_NOOP3})
338
\li \c {QT_TR_NOOP} (\c {=QT_TR_NOOP})
339
\li \c {QT_TRID_NOOP} (\c {=QT_TRID_NOOP})
340
\li \c {QT_TRANSLATE_NOOP} (\c {=QT_TRANSLATE_NOOP})
341
\li \c {QT_TRANSLATE_NOOP3} (\c {=QT_TRANSLATE_NOOP3})
342
\li \c {QT_TR_NOOP_UTF8} (\c {=QT_TR_NOOP_UTF8})
343
\li \c {QT_TRANSLATE_NOOP_UTF8} (\c {=QT_TRANSLATE_NOOP_UTF8})
344
\li \c {QT_TRANSLATE_NOOP3_UTF8} (\c {=QT_TRANSLATE_NOOP3_UTF8})
345
\li \c {findMessage} (\c {=findMessage})
346
\li \c {qtTrId} (\c {=qtTrId})
347
\li \c {tr} (\c {=tr})
348
\li \c {trUtf8} (\c {=trUtf8})
349
\li \c {translate} (\c {=translate})
350
\li \c {qsTr} (\c {=qsTr})
351
\li \c {qsTrId} (\c {=qsTrId})
352
\li \c {qsTranslate} (\c {=qsTranslate})
353
\endlist
354
\row
355
\li \c {-ts <ts-file>...}
356
\li Specify the output files. This overrides \c TRANSLATIONS.
357
\row
358
\li \c {-version}
359
\li Display the version of \c lupdate and exit.
360
\endtable
361
362
\section1 Examples
363
364
\section2 Using lupdate with CMake
365
366
When building with CMake, use \l{CMake Commands in Qt6 LinguistTools}
367
{CMake commands} to add translations on targets to the CMakeLists.txt
368
file, and then build the targets.
369
370
Select one of the following options:
371
372
\list
373
\li Use \l qt_add_translations on a target, such as \e app.
374
This calls \l qt_add_lupdate and \l qt_add_lrelease.
375
\li Use \c qt_add_lupdate on a target.
376
\endlist
377
378
Build a target (for example, \c app_lupdate) to update the .ts
379
files for it. To update the .ts files for all targets, build the
380
target \c {update_translations}.
381
382
\section2 Using lupdate with qmake
383
384
To generate a translation file for a single QML file:
385
386
\badcode
387
lupdate main.qml -ts main_en.ts
388
\endcode
389
390
To make a translation file for another language, for example French,
391
copy main_en.ts to main_fr.ts, and translate the strings in the
392
French TS file.
393
394
\c lupdate processes QML files that are listed in the \c .qrc file:
395
396
\badcode
397
RESOURCES += qml.qrc
398
\endcode
399
400
To have all QML files processed by \c lupdate:
401
402
\badcode
403
lupdate application.qrc -ts myapp_en.ts
404
\endcode
405
406
To process all QML files in the current working directory (or its subfolders)
407
without using a \c .qrc file:
408
409
\badcode
410
lupdate . -extensions qml -ts myapp_en.ts
411
\endcode
412
413
To check for translatable strings in both QML and C++ source files:
414
415
\badcode
416
lupdate qml.qrc filevalidator.cpp -ts myapp_en.ts
417
\endcode
418
419
To generate .ts files that will be used for English and French without
420
specifying the languages in the project file:
421
422
\badcode
423
lupdate qml.qrc filevalidator.cpp -ts myapp_en.ts myapp_fr.ts
424
\endcode
425
426
Give the TS files to the translator who uses \QL to read the files and
427
insert the translations.
428
429
\section1 XLIFF format files
430
431
The TS file format is a simple human-readable XML format that you
432
can use with version control systems. In addition, \c lupdate can
433
process Localization Interchange File Format (XLIFF) files (\c .xlf).
434
435
\note Only XLIFF versions 1.1 and 1.2 are currently supported.
436
437
You can open and edit XLIFF files in \QL.
438
*/
439
440
/*!
441
\page linguist-lrelease.html
442
\target lrelease
443
444
\previouspage Using lupdate
445
\nextpage Using lconvert
446
447
\title Using lrelease
448
449
The \c lrelease command line tool produces QM files out of TS files. The
450
QM file format is a compact binary format that the localized application
451
uses. It provides extremely fast lookup for translations.
452
453
When building with qmake, specify the files to process at the command line
454
or in a .pro file.
455
456
When building with CMake, use \l{CMake Commands in Qt6 LinguistTools}
457
{CMake commands} to add targets that create or update TS files and
458
transform them into QM files. The \c lrelease tool is run with the
459
\l {lrelease options}{options} you pass to the commands when you build
460
the target.
461
462
Run \c lrelease whenever you want to release the application, from the
463
initial test version through to the final release version. The application
464
does not need QM files to run, but if they are available, the application
465
detects them and uses them automatically.
466
467
\note The \c lrelease tool only incorporates translations that you
468
mark as \e finished. Otherwise, it uses the original text instead.
469
470
\section1 lrelease syntax
471
472
\badcode
473
lrelease [options] -project project-file
474
lrelease [options] ts-files [-qm qm-file]
475
\endcode
476
477
Where:
478
479
\list
480
\li \c options means one or several \l {lrelease options}.
481
\li \c project-file is the project configuration file.
482
\li \c ts-files are the TS files to use as input for the QM files.
483
\li \c qm-file is the name of the QM file to generate.
484
\endlist
485
486
\note Passing .pro files to \c lrelease is deprecated. Use the
487
\c lrelease-pro tool or the \c lrelease.prf feature when using qmake.
488
489
To view the latest help, enter:
490
491
\badcode
492
lrelease -help
493
\endcode
494
495
\section2 lrelease options
496
497
\table
498
\header
499
\li Option
500
\li Action
501
\row
502
\li \c {-help}
503
\li Display up-to-date help information and exit.
504
\row
505
\li \c {-idbased}
506
\li Deprecated. The flag is not required anymore and will be removed
507
in a future version. It was used to enable ID based translation.
508
\row
509
\li \c {-compress}
510
\li Compress the QM files.
511
\row
512
\li \c {-nounfinished}
513
\li Do not include unfinished translations.
514
\row
515
\li \c {-fail-on-unfinished}
516
\li Generate an error if unfinished translations are found
517
\row
518
\li \c {-removeidentical}
519
\li If the translated text is the same as the source text, exclude the
520
message.
521
\row
522
\li \c {-markuntranslated <prefix>}
523
\li If a message has no real translation, use the source text
524
prefixed with the given string instead.
525
\row
526
\li \c {-project <filename>}
527
\li Name of a file containing the project's description in JSON format.
528
You can use the \c lprodump tool to generate the file from a .pro
529
file.
530
\row
531
\li \c {-silent}
532
\li Do not explain what is being done.
533
\row
534
\li \c {-verbose}
535
\li Explain what is being done (default).
536
\row
537
\li \c {-version}
538
\li Display the version of \c lrelease and exit.
539
\endtable
540
541
\section1 Examples
542
543
\section2 Using lrelease with CMake
544
545
When building with CMake, use \l{CMake Commands in Qt6 LinguistTools}
546
{CMake commands} to add translations on targets to the CMakeLists.txt
547
file, and then build the targets.
548
549
Select one of the following options:
550
551
\list
552
\li Use \l qt_add_translations on a target, such as \e app.
553
This calls \l qt_add_lupdate and \l qt_add_lrelease.
554
\li Use \c qt_add_lrelease on a target.
555
\endlist
556
557
Build a target (for example, \c app_lrelease) to update the .qm
558
files for it. To update the .qm files for all targets, build the
559
target \c {release_translations}.
560
561
\section2 Using lrelease with qmake
562
563
To run \c lrelease without specifying a project file:
564
565
\badcode
566
lrelease.exe main_en.ts languages\main_fr.ts
567
\endcode
568
*/
569
570
/*!
571
\page linguist-lconvert.html
572
\target lconvert
573
574
\previouspage Using lrelease
575
\nextpage Using lconvert
576
577
\title Using lconvert
578
579
The \c lconvert command line tool filters and converts translation data
580
files.
581
582
It supports the following file formats:
583
\list
584
\li \c pot - GNU Gettext localization template files
585
\li \c qph - Qt Linguist Phrase Book
586
\li \c ts - Qt translation sources
587
\li \c po - GNU Gettext localization files
588
\li \c qm - Compiled Qt translations
589
\li \c xlf - XLIFF localization files
590
\endlist
591
592
\section1 lconvert syntax
593
594
\badcode
595
lconvert [options] <infile> [<infile>...]
596
\endcode
597
598
Where:
599
600
\list
601
\li \c options means one or several \l {lconvert options}.
602
\li \c infile is an input file. You can specify multiple input files.
603
\endlist
604
605
If you specify multiple input files, they are merged with translations from
606
later files taking precedence.
607
608
To view the latest \c lconvert help, enter:
609
610
\badcode
611
lconvert -help
612
\endcode
613
614
\section2 lconvert options
615
616
\table
617
\header
618
\li Option
619
\li Action
620
\row
621
\li \c -h \br \c -help
622
\li Display up-to-date help information and exit.
623
\row
624
\li \c {-i <infile>} \br \c {-input-file <infile>}
625
\li Specify an input file. Use this option if \c{<infile>} starts with a dash.
626
Use this option several times to merge inputs.
627
May be \c {-} (standard input) for use in a pipe.
628
\row
629
\li \c {-o <outfile>} \br \c {-output-file <outfile>}
630
\li Specify an output file. Default is \c {-} (standard output).
631
\row
632
\li \c {-if <informat>} \br \c {-input-format <format>}
633
\li Specify input format for subsequent input files.
634
The format is auto-detected from the file name and defaults to \c ts.
635
\row
636
\li \c {-of <outformat>} \br \c {-output-format <outformat>}
637
\li Specify output format. See \c -if.
638
\row
639
\li \c {-drop-tags <regexp>}
640
\li Drop named extra tags when writing \c TS or \c XLIFF files.
641
You can specify this option repeatedly.
642
\row
643
\li \c {-drop-translations}
644
\li Drop existing translations and reset the status to \c unfinished.
645
That implies \c {--no-obsolete}.
646
\row
647
\li \c {-source-language <language>[_<region>]}
648
\li Specify/override the language of the source strings. Defaults to
649
POSIX if not specified and the file does not name it yet.
650
\row
651
\li \c {-target-language <language>[_<region>]}
652
\li Specify or override the language of the translation.
653
By default, the target language is read from the file content or
654
guessed from the file name.
655
\row
656
\li \c {-no-obsolete}
657
\li Drop obsolete messages.
658
\row
659
\li \c {-no-finished}
660
\li Drop finished messages.
661
\row
662
\li \c {-no-untranslated}
663
\li Drop untranslated messages.
664
\row
665
\li \c {-sort-contexts}
666
\li Sort contexts in the output \c TS file alphabetically.
667
\row
668
\li \c {-sort-messages}
669
\li Sort messages in a context alphabetically in \c TS files.
670
\row
671
\li \c {-locations {absolute|relative|none}}
672
\li Override how source code references are saved in \c TS files.
673
Default is \c absolute.
674
\row
675
\li \c {-no-ui-lines}
676
\li Drop line numbers from references to \c UI files.
677
\row
678
\li \c {-pluralonly}
679
\li Drop non-plural form messages.
680
\row
681
\li \c {-verbose}
682
\li Explain what is being done.
683
\endtable
684
685
\section1 Examples
686
687
\section2 Convert TS file to XLIFF
688
689
To convert a single TS file to XLIFF, run the following command in the
690
terminal:
691
692
\badcode
693
lconvert -o myapp_de.xlf myapp_de.ts
694
\endcode
695
696
\section2 Merge multiple QM files
697
698
The following command merges multiple QM files into \c {full_de.qm}:
699
700
\badcode
701
lconvert -o full_de.qm qtbase_de.qm myapp_de.qm mylib_de.qm
702
\endcode
703
704
\section2 Using lconvert with CMake
705
706
To call \c lconvert when configuring or building your CMake project, load
707
the \c Qt6LinguistTools package and use \c
708
{$<TARGET_FILE_NAME:Qt6::lconvert>} for locating the \c lconvert executable.
709
710
The following example adds a custom target \c xlf_de that converts a single
711
TS file to XLIFF.
712
713
\badcode
714
find_package(Qt6 REQUIRED COMPONENTS LinguistTools)
715
716
add_custom_command(
717
OUTPUT myapp_de.xlf
718
COMMAND $<TARGET_FILE:Qt6::lconvert> -o myapp_de.xlf myapp_de.ts
719
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/myapp_de.ts"
720
VERBATIM
721
)
722
723
add_custom_target(xlf_de
724
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/myapp_de.xlf"
725
)
726
\endcode
727
*/
728
729
/*!
730
\page linguist-lcheck.html
731
\target lcheck
732
\previouspage Using lconvert
733
\nextpage Translators
734
735
\title Using lcheck
736
737
The \c lcheck command line tool validates Qt \c {TS} translation files and
738
produces a human-readable report. It is part of the Qt Linguist toolchain
739
and is intended for batch or CI usage to catch common localization issues
740
early. By default, \c lcheck runs a set of checks and returns a non-zero
741
exit code if at least one enabled check fails.
742
743
The default checks are:
744
745
\list
746
\li \b Accelerator check — Verifies that the number of ampersands
747
(mnemonics) in source and translation match.
748
\li \b Surrounding whitespace check — Verifies that leading and trailing
749
whitespace of source and translation match.
750
\li \b Ending punctuation check — Verifies that source and translation
751
end with the same punctuation.
752
\li \b Place marker check — Verifies consistent usage of \c {%1}, \c {%2},
753
and so on, between source and translation.
754
\endlist
755
756
Each check can be disabled individually using command line options.
757
758
\section1 lcheck syntax
759
760
\badcode
761
lcheck [options] -o report-output-file ts-file
762
lcheck [options] ts-file
763
\endcode
764
765
Where:
766
767
\list
768
\li \c options means one or several \l {lcheck options}.
769
\li \c ts-file is the \c {TS} file to validate.
770
\li \c report-output-file is the path of the file to write the report to.
771
If omitted, the report is written to the standard error stream.
772
\endlist
773
774
To view the latest help, enter:
775
776
\badcode
777
lcheck -help
778
\endcode
779
780
\section2 lcheck options
781
782
\table
783
\header
784
\li Option
785
\li Action
786
\row
787
\li \c {-help}
788
\li Display up-to-date help information and exit.
789
\row
790
\li \c {-no-accelerator}
791
\li Disable the accelerator (ampersand) consistency check.
792
\row
793
\li \c {-no-punctuation}
794
\li Disable the ending punctuation consistency check.
795
\row
796
\li \c {-no-place-marker}
797
\li Disable the check that ensures \c {%1}, \c {%2}, … are used
798
consistently between source and translation.
799
\row
800
\li \c {-no-whitespaces}
801
\li Disable the surrounding whitespace consistency check.
802
\row
803
\li \c {-check-finished}
804
\li Also check messages marked as \e finished. By default, finished
805
translations are not checked.
806
\row
807
\li \c {-o <outfile>}
808
\li Write the validation report to \c <outfile>. If not specified, the
809
report is written to standard error.
810
\row
811
\li \c {-version}
812
\li Display the version of \c lcheck and exit.
813
\endtable
814
815
\note The process exit status is non-zero if any enabled check fails. This
816
makes \c lcheck suitable for use in CI pipelines.
817
818
\section1 Examples
819
820
\section2 Write a report to a file
821
822
\badcode
823
lcheck -o lcheck_report.txt translations/myapp_de.ts
824
\endcode
825
826
\section2 Disable selected checks
827
828
The following command runs all checks except accelerator and punctuation:
829
830
\badcode
831
lcheck -no-accelerator -no-punctuation translations/myapp_de.ts
832
\endcode
833
834
\section2 Check finished translations as well
835
836
\badcode
837
lcheck -check-finished translations/myapp_de.ts
838
\endcode
839
840
\section2 Use lcheck in a CI step
841
842
\badcode
843
lcheck translations/myapp_de.ts && echo "Translations OK" || echo "Issues found"
844
\endcode
845
846
\section2 Using lcheck with CMake
847
848
To call \c lcheck when configuring or building your CMake project, load
849
the \c Qt6LinguistTools package and use \c {$<TARGET_FILE:Qt6::lcheck>}
850
to locate the \c lcheck executable.
851
852
The following example adds a custom target \c check_translations that runs
853
\c lcheck over a TS file and writes a report next to the build artifacts.
854
855
\badcode
856
find_package(Qt6 REQUIRED COMPONENTS LinguistTools)
857
858
add_custom_command(
859
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/lcheck_report.txt"
860
COMMAND $<TARGET_FILE:Qt6::lcheck>
861
-o "${CMAKE_CURRENT_BINARY_DIR}/lcheck_report.txt"
862
"${CMAKE_CURRENT_SOURCE_DIR}/translations/myapp_de.ts"
863
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/translations/myapp_de.ts"
864
VERBATIM
865
)
866
867
add_custom_target(check_translations
868
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/lcheck_report.txt"
869
)
870
\endcode
871
872
\section2 Using lcheck with qmake
873
874
You can run \c lcheck directly on a TS file without specifying a project file:
875
876
\badcode
877
lcheck translations/myapp_de.ts
878
\endcode
879
*/
880
881
/*!
882
\page linguist-translators.html
883
884
\previouspage Using lcheck
885
\nextpage Qt Linguist user interface
886
887
\title Translators
888
889
\image front-ui.png
890
891
\QL is a tool for translating strings in Qt applications. Once you have
892
installed Qt, you can start \QL in the same way as any other application on
893
the development host.
894
895
\note You can obtain an installer for \QL only (without the entire Qt SDK)
896
from \l {https://download.qt.io/linguist_releases/}. The installer is
897
available for Windows, and works with Qt 6.
898
899
To address issues that arise from the subtleties and complexities of
900
human language, translators and developers may need to:
901
902
\list
903
\li Translate a single phrase into several different forms depending on
904
context. For example, \e open in English might become \e{\ouml}\e{ffnen},
905
\e {open file}, or \e aufbauen, \e {open internet connection}, in German.
906
907
\li Change the mnemonic characters in keyboard shortcuts without introducing
908
conflicts. For example, \c \&Quit in English becomes \e Avslutt in
909
Norwegian, which does not contain the letter \e Q. You cannot use a
910
letter that is already in use unless you change several shortcuts.
911
912
\li Rephrase strings that contain variables. For example, you might need to
913
place the variables in a different order when you translate the string
914
\e {The 25 files selected will take 63 seconds to process}, where the
915
two numbers are inserted programmatically at runtime.
916
\endlist
917
918
For more information about how to use \QL to translate applications, see:
919
920
\list
921
\li \l {Qt Linguist user interface}
922
\li \l {Translating strings}
923
\li \l {Selecting context or label to translate}
924
\li \l {Selecting strings to translate}
925
\li \l {Viewing strings in context}
926
\li \l {Reusing translations}
927
\li \l {Validating translations}
928
\li \l {Translating multiple languages simultaneously}
929
\li \l {AI translation}
930
\endlist
931
*/
932
933
/*!
934
\page linguist-ui.html
935
936
\previouspage Translators
937
\nextpage Translating strings
938
939
\title Qt Linguist user interface
940
941
The \QL main window contains a menu bar and the following views:
942
943
\list
944
945
\li \uicontrol Context/Label (\key F6) lists translation contexts or labels.
946
947
\li \uicontrol Strings (\key F7) lists translatable strings in the
948
selected context.
949
950
\li \uicontrol {Sources and Forms} (\key F9) displays the selected
951
string in the source code.
952
953
\li Translation area displays the selected string and enables you to
954
enter a translation for it.
955
956
\li \uicontrol {Phrases and guesses} (\key F10) lists possible
957
translations for the current string.
958
959
\li \uicontrol Warnings (\key F8) lists translated strings that fail
960
validation tests.
961
962
\endlist
963
964
\image linguist.webp {Qt Linguist UI}
965
966
The translation area (1) is always visible. To show or hide the other views,
967
select \uicontrol View > \uicontrol Views, or use keyboard shortcuts.
968
You can drag the views by their title bars and arrange them around the
969
translation area or even outside the main window.
970
*/
971
972
/*!
973
\page linguist-translating-strings.html
974
975
\previouspage Qt Linguist user interface
976
\nextpage Selecting context or label to translate
977
978
\title Translating strings
979
980
Open translation source (TS) files in \QL for translation. TS files are
981
human-readable XML files containing source phrases and their translations.
982
TS files are usually created and updated by \c lupdate. If you do not have
983
a TS file, see \l {Creating translation files} to learn how to generate one.
984
985
You can use \QL also to translate files in the international XML
986
Localization Interchange File Format (XLIFF) that are generated by other
987
programs. However, for standard Qt projects, only the TS file format is
988
used. Only XLIFF versions 1.1 and 1.2 are currently supported.
989
990
\QL displays the target language in the translation area, and adapts the
991
number of input fields for plural forms accordingly. When you open several
992
TS files to translate simultaneously, the \uicontrol Translator and
993
\uicontrol {Translator comment} fields are displayed for each language.
994
For more information about setting the location information, see
995
\l{Changing the target locale}.
996
997
If the developer provides a disambiguating comment, you can see it in the
998
\uicontrol {Developer comments} field.
999
1000
To translate strings:
1001
\list 1
1002
1003
\li Select \uicontrol File > \uicontrol Open to load a TS file.
1004
1005
\li Select a context in the \uicontrol Context view to display translatable
1006
strings in the \uicontrol Strings view.
1007
1008
\image linguist-ui.webp {}
1009
1010
\li Select a string to display it in the \uicontrol {Source text} field
1011
in the translation area. The whitespace within the source text is
1012
visualized.
1013
1014
\li Enter the translation of the current string in the \uicontrol Translation
1015
field.
1016
1017
Double-click an existing translation in the
1018
\uicontrol {Phrases and guesses} field to use it as the translation
1019
for the current string. \QL reads the phrases from phrase books and
1020
bases the guesses on existing translations of similar phrases in the
1021
TS file.
1022
1023
\li Optionally, enter a comment for other translators in the
1024
\uicontrol {Translator comment} field.
1025
1026
\li To accept the translation, press \key {Ctrl+Enter}, select
1027
\inlineimage linguist-doneandnext.png
1028
, or click the icon to the left of the selected source string in the
1029
string list.
1030
1031
\li Select \uicontrol File > \uicontrol Save to save your work.
1032
1033
\endlist
1034
1035
Repeat this process until all strings in the string list are marked with
1036
\inlineimage linguist-check-on.png
1037
(\uicontrol {Accepted/Correct}) or
1038
\inlineimage linguist-check-warning.png
1039
(\uicontrol {Accepted/Warnings}). Then select the next context and continue.
1040
1041
To view the number of words and characters in the source text and in the
1042
translated text, select \uicontrol View > \uicontrol Statistics.
1043
1044
Select \uicontrol File > \uicontrol Release to create a QM
1045
file with the same base name as the current translation source file.
1046
The \c lrelease tool performs the same function on \e all of an
1047
application's translation source files.
1048
1049
To print the translation source and the translations, select \uicontrol File >
1050
\uicontrol Print.
1051
1052
To quit \QL, select \uicontrol File > \uicontrol Exit.
1053
1054
\section1 Moving between translatable strings
1055
1056
To move to the next unfinished translation, select
1057
\inlineimage nextunfinished.png
1058
(\uicontrol {Next Unfinished}) or press \key{Ctrl+J}.
1059
1060
To move to the next source text, select \inlineimage next.png
1061
, press \key{Ctrl+Shift+J}, or select \uicontrol Translation >
1062
\uicontrol Next.
1063
1064
\section1 Phrases that require multiple translations depending on context
1065
1066
The same phrase may occur in more than one context without conflict. When
1067
you reach another occurrence of a translated phrase, \QL provides
1068
the previous translation as a possible translation in the
1069
\uicontrol {Phrases and guesses} view.
1070
1071
If a phrase occurs more than once within a particular context, it appears
1072
only once in the \uicontrol Context view, and the translation is applied
1073
to every occurrence within the context. If the same phrase means different
1074
things within the same context, the developer must provide a comment for
1075
each occurrence of the phrase. The duplicate phrases appear in the
1076
\uicontrol Context view. The developer's comments appear in the translation
1077
area on a light blue background.
1078
1079
\section1 Changing keyboard shortcuts
1080
1081
A keyboard shortcut is a key combination that performs an action.
1082
1083
\section2 Alt key shortcuts
1084
1085
In menu item and button text, a \e mnemonic character (marked by underlining)
1086
indicates that pressing \key Alt or \key Ctrl with the underlined character
1087
performs the same action as clicking the menu item or pressing the button.
1088
1089
For example, applications often use \e F as the mnemonic character in the
1090
\uicontrol {File} menu, so you can either click the menu item or press
1091
\key {Alt+F} to open the menu. The mnemonic character in the translatable
1092
string is prefixed with an ampersand: \c {\&File}. The translation for the
1093
string should also have an ampersand in it, preferably in front of the same
1094
character.
1095
1096
You can determine the meaning of an \key Alt key shortcut from the phrase
1097
that contains the ampersand. You can use another mnemonic character if the
1098
translated phrase does not contain the current one or if it is used in
1099
the translation of some other shortcut in the context. Some key shortcuts,
1100
usually those on the menu bar, may apply in other contexts.
1101
1102
\section2 Ctrl key shortcuts
1103
1104
\key Ctrl key shortcuts can exist independently of any visual control.
1105
Typically, they invoke actions in menus that would require multiple
1106
keystrokes or mouse clicks or actions that do not appear in any menu
1107
or on any button. For example, the \uicontrol {File} menu might contain a
1108
\uicontrol {\underline{N}ew Ctrl+N} item that you can invoke by pressing
1109
\key {Ctrl+N} even when the \uicontrol {File} menu is closed.
1110
1111
Each \key Ctrl key shortcut appears in the \uicontrol Strings view
1112
as a separate string. For example, \key{Ctrl+Enter}. Since
1113
the string does not have a context to give it meaning, such as
1114
the context of the phrase in which an \key Alt key shortcut appears,
1115
you must rely on the developer to include a \l{QObject::tr()}
1116
{disambiguation comment} to explain the action the \key Ctrl key
1117
shortcut performs. The comment appears under \uicontrol {Developer comments}
1118
in the translation area below the \uicontrol {Source text} field.
1119
1120
Ideally, you can copy translations for \key Ctrl key shortcuts by
1121
selecting \uicontrol Translation > \uicontrol {Copy from source text}.
1122
However, if the character does not make sense in the target language,
1123
change it. Whichever character (alpha or digit) you choose, use the form
1124
\key {Ctrl+} followed by the upper case character. Qt automatically displays
1125
the correct name at runtime. As with \key Alt key shortcuts, if you change
1126
the character, make sure that it does not conflict with any other
1127
\key Ctrl key shortcut.
1128
1129
\note Do not translate the \key Alt, \key Ctrl or \key Shift parts of
1130
the shortcuts, as Qt recognizes them and automatically translates them
1131
for supported languages.
1132
1133
\section1 Handling numbered arguments and plural forms
1134
1135
A numbered argument is a placeholder that will be replaced with text at
1136
runtime. It appears in a source string as a percent sign followed by
1137
a digit. For example, in the \c{After processing file %1, file %2
1138
is next in line} string, \c{%1} and \c{%2} are numbered arguments that
1139
are replaced with the first and second file names at runtime. The
1140
same numbered arguments must appear in the translation, but not
1141
necessarily in the same order. A German translation of the string
1142
might reverse the phrases, for example \c{Datei %2 wird bearbeitet, wenn
1143
Datei %1 fertig ist}. Both numbered arguments appear in the
1144
translation, but in the reverse order. A numbered argument is always
1145
replaced by the same text in the translations, regardless of the position
1146
in the argument sequence in the source string.
1147
1148
The use of numbered arguments is often accompanied by the use of
1149
plural forms in the source text. In many languages, the form of the
1150
text will depend on the value shown, and more than one translation
1151
is required. If the developers have marked up the source text in
1152
correct way, fields for each of the possible plural forms will be
1153
available in the translation area. For more information, see
1154
\l{Writing Source Code for Translation}.
1155
1156
\section1 Handling numeric character references (NCR) in translations
1157
1158
Select \uicontrol {NCR mode} to toggle the representation of
1159
numeric character references in both the source text and the translation
1160
fields. When selected, special characters in the text are displayed as their
1161
corresponding NCRs (for examlple,   for a non-breaking space). Otherwise, the
1162
characters appear in their standard visual form. This feature is useful
1163
for instance to maintain the same special characters (such as
1164
emojis, special spaces) in both the source text and its translations.
1165
1166
\section1 Changing the target locale
1167
1168
You can set the locale information explicitly in \uicontrol Edit >
1169
\uicontrol {Translation File Settings}. If the target language and country
1170
are not explicitly set when you open a translation source file, \QL
1171
attempts to deduct them from the translation source file name. This
1172
requires that the translation files adhere to the following file name
1173
convention:
1174
\c appname_language[_country].ts, where:
1175
1176
\list
1177
\li \c language is an ISO 639 language code in lowercase.
1178
\li \c country is an ISO 3166 two-letter country code in uppercase.
1179
\endlist
1180
1181
If this attempt to resolve the target language and country fails, the
1182
\uicontrol {Translation File Settings} window opens.
1183
1184
For example, \c app_de.ts sets the
1185
target language to German, and \c app_de_CH.ts sets the target language to
1186
German and the target country to Switzerland. This also helps loading
1187
translations for the current locale automatically. For more information, see
1188
\l{Enable Translation}.
1189
1190
\image linguist-translationfilesettings.png
1191
*/
1192
1193
/*!
1194
\page linguist-selecting-context.html
1195
1196
\previouspage Translating strings
1197
\nextpage Selecting strings to translate
1198
1199
\title Selecting context or label to translate
1200
1201
The \uicontrol Context/Label view lists the contexts (\uicontrol {Text based}) or
1202
labels (\uicontrol {ID based}) in which strings to be translated
1203
appear. The text-based translations are grouped into contexts, while ID-based
1204
translations are grouped into labels (see \l{Grouping ID-Based Translations}).
1205
The \uicontrol Context/Label lists the \e groups (that is, context or labels)
1206
based on the selected tab:
1207
\list
1208
\li Upon switching to the \uicontrol{Text-Based} tab,
1209
\uicontrol Context lists the context names in
1210
alphabetical order. Each context is the name of a QML type or a subclass of
1211
QObject.
1212
\li Upon switching to the \uicontrol{ID-Based} tab,
1213
\uicontrol Label lists the label names in
1214
alphabetical order. More info on labels can be found in \l{Grouping ID-Based Translations}.
1215
\endlist
1216
1217
\image linguist-context-view.webp {Context/Label view}
1218
1219
The following icons indicate the current translation state for each group:
1220
1221
\table
1222
\header
1223
\li State
1224
\li Icon
1225
\li Description
1226
1227
\row
1228
\li Accepted/Correct
1229
\li \inlineimage linguist-check-on.png
1230
\li All strings in the group have been translated, and all the
1231
translations passed the \l{Validating Translations}{validation tests}.
1232
1233
\row
1234
\li Accepted/Warnings
1235
\li \inlineimage linguist-check-warning.png
1236
\li All strings in the group have been translated or marked as translated,
1237
but at least one translation failed the validation tests.
1238
In the \uicontrol Strings view, you can see which string failed the test.
1239
1240
\row
1241
\li Not Accepted
1242
\li \inlineimage linguist-check-off.png
1243
\li At least one string in the group has not been translated or is not
1244
marked as translated.
1245
1246
\row
1247
\li Obsolete
1248
\li \inlineimage linguist-check-obsolete.png
1249
\li None of the translated strings appears in the group any more. This
1250
usually means the context or label no longer exists in the application.
1251
\endtable
1252
1253
The \uicontrol Items column displays the total number of translatable strings in
1254
the group and the number of translated strings, separated by a slash (/).
1255
If the numbers are equal, all the translatable strings in the group have
1256
translations.
1257
*/
1258
1259
/*!
1260
\page linguist-selecting-strings.html
1261
1262
\previouspage Selecting context or label to translate
1263
\nextpage Viewing strings in context
1264
1265
\title Selecting strings to translate
1266
1267
The \uicontrol Strings view lists all the translatable strings in the
1268
current group (that is, context or label) and their translation acceptance
1269
state. Select a string to view and edit it in the translation area.
1270
1271
\image linguist-strings-view.webp {Strings view}
1272
1273
Click the icon in front of a string to change its translation acceptance
1274
state. A tick mark, green or yellow, means the string has an accepted
1275
translation. A question mark means either that the translation does not
1276
exist or you have not accepted it.
1277
1278
The following icons indicate the current translation state for each string:
1279
1280
\target String Translation States
1281
1282
\table
1283
\header
1284
\li State
1285
\li Icon
1286
\li Description
1287
1288
\row
1289
\li Accepted/Correct
1290
\li \inlineimage linguist-check-on.png
1291
\li The source string has a translation (possibly empty). You accepted
1292
the translation, and it passes all the \l{Validating Translations}
1293
{validation tests}. Click the icon to revoke acceptance of the
1294
translation. The state becomes \uicontrol {Not Accepted} if the string
1295
has a translation or \uicontrol {No Translation} if the translation is
1296
empty. If \c{lupdate} changes the contents of a string, its acceptance
1297
state becomes \uicontrol {Not Accepted}.
1298
1299
\row
1300
\li Accepted/Warnings
1301
\li \inlineimage linguist-check-warning.png
1302
\li You accepted the translation, but it does not pass all the validation
1303
tests. The \uicontrol Warnings view shows where it failed. If you click
1304
the icon to revoke acceptance of the translation, the state becomes
1305
\uicontrol {Validation Failures}.
1306
1307
\row
1308
\li Not Accepted
1309
\li \inlineimage linguist-check-off.png
1310
\li The string has a translation that passes all the validation tests, but
1311
you have not yet accepted the translation. Click the icon or press
1312
\key{Ctrl+Enter} to accept the translation. The state becomes
1313
\uicontrol {Accepted/Correct}.
1314
1315
\row
1316
\li No Translation
1317
\li \inlineimage linguist-check-empty.png
1318
\li The string does not have a translation. If you click the icon to accept
1319
the empty translation, the state becomes \uicontrol {Accepted/Correct}.
1320
1321
\row
1322
\li Validation Failures
1323
\li \inlineimage linguist-danger.png
1324
\li The string has a translation, but the translation does not pass all the
1325
validation tests. The \uicontrol Warnings view shows the validation test
1326
failures. Click on the icon or press \key{Ctrl+Enter} to
1327
accept the translation even with validation failures. The state becomes
1328
\uicontrol {Accepted/Warnings}. Usually, you should fix the causes of the
1329
validation failures. The state will automatically become
1330
\uicontrol {Not Accepted} when you fix all failures.
1331
1332
\row
1333
\li Obsolete
1334
\li \inlineimage linguist-check-obsolete.png
1335
\li The string is obsolete. It is no longer used in the context.
1336
See \l{Using lupdate} for instructions on how to remove obsolete
1337
messages from the file.
1338
1339
\endtable
1340
*/
1341
1342
/*!
1343
\page linguist-viewing-strings-in-context.html
1344
1345
\previouspage Selecting strings to translate
1346
\nextpage Reusing translations
1347
1348
\title Viewing strings in context
1349
1350
If \QL can access the source files containing the translatable strings, the
1351
\uicontrol {Sources and Forms} view shows the source context of the current
1352
string in the \uicontrol Strings view. It highlights the source code line
1353
that contains the current string. If \QL cannot find the source file, it
1354
shows the expected absolute file path.
1355
1356
If the source context shows the wrong source line, the translation file might
1357
be out of sync with the source files. For more information about how to sync
1358
the files, see \l{Using lupdate}.
1359
1360
\QD stores UI forms in special UI files (.ui). \QL attempts to show the
1361
translations in the forms.
1362
*/
1363
1364
/*!
1365
\page linguist-reusing-translations.html
1366
1367
\previouspage Viewing strings in context
1368
\nextpage Validating translations
1369
1370
\title Reusing translations
1371
1372
If the translated text is similar to the source text, select
1373
\uicontrol Translation > \uicontrol {Copy from source text}
1374
(or press \key{Ctrl+B}) to copy the source text into the
1375
translation area.
1376
1377
\e {Phrase books} provide a common set of translations
1378
to help ensure consistency. A phrase book is a set of source phrases, target
1379
(translated) phrases, and optional definitions. Typically, one phrase book
1380
is created per language and family of applications. Phrase books avoid
1381
duplication of effort since they contain translations for a family of
1382
applications.
1383
1384
The \uicontrol {Phrases and guesses} view displays the current string and its
1385
phrase book translations. If the current string is the same as or similar to
1386
a translated string, the view also lists the string and its translation.
1387
1388
To copy a translation from the \uicontrol {Phrases and guesses} view to the
1389
translation area, double-click it or select it and press \key Enter.
1390
1391
\section1 Batch translation
1392
1393
\image linguist-batchtranslation.png
1394
1395
Use the batch translation feature to automatically translate source
1396
texts that are also in a phrase book. To configure which phrase books to use
1397
in what order during the batch translation process, select \uicontrol Edit >
1398
\uicontrol {Batch Translation}. You can include only entries with no
1399
current translation and mark batch translated entries as \uicontrol Accepted.
1400
1401
\section1 Creating and editing phrase books
1402
1403
Phrase book files are human-readable XML files containing standard phrases
1404
and their translations. \QL creates and update the files. You can use them
1405
for any number of projects and applications.
1406
1407
To create a new phrase book, select \uicontrol Phrases > \uicontrol {New Phrase Book}.
1408
1409
\image linguist-phrasebookdialog.png
1410
1411
To open a phrase book, select \uicontrol Phrases > \uicontrol {Open Phrase Book}, and
1412
then select the Qt phrase book file (.qph) to open.
1413
1414
To view and change open phrase books, select \uicontrol Phrases >
1415
\uicontrol {Edit Phrase Book}.
1416
1417
To add a new phrase, select \uicontrol {New Entry} (or press \key {Alt+N}) and
1418
type in a new source phrase, the translation, and an optional definition.
1419
This is useful to distinguish different translations of the same source
1420
phrase.
1421
1422
To add the translation you are working on to the current phrase book, select
1423
\uicontrol Phrases > \uicontrol {Add to Phrase Book} or press \key{Ctrl+T}. If multiple
1424
phrase books are loaded, you have to select one.
1425
1426
If you detect an error in a phrase book entry in the
1427
\uicontrol {Phrases and guesses} view, you can edit by right
1428
clicking it and selecting \uicontrol Edit. After fixing the
1429
error press \key{Enter} to leave the editing mode.
1430
1431
To delete a phrase, select it in the \uicontrol {Source phrase} list, and then
1432
select \uicontrol {Remove Entry}.
1433
1434
To print an open phrase book, select \uicontrol Phrases >
1435
\uicontrol {Print Phrase Book}.
1436
*/
1437
1438
/*!
1439
\page linguist-validating-translations.html
1440
1441
\previouspage Reusing translations
1442
\nextpage Translating multiple languages simultaneously
1443
1444
\title Validating translations
1445
1446
\QL provides the following validation tests for translations:
1447
1448
\list
1449
\li \e {Accelerator validation} detects translated phrases
1450
that do not have an ampersand when the source phrase does and vice
1451
versa.
1452
\li \e {Punctuation validation} detects differences in the
1453
terminating punctuation between source and translated phrases when
1454
this may be significant. For example, warns if the source phrase
1455
ends with an ellipsis, exclamation mark or question mark, and the
1456
translated phrase does not, and vice versa.
1457
\li \e {Phrases validation} detects source phrases that are
1458
also in the phrase book but whose translation differs from that
1459
in the phrase book.
1460
\li \e {Place marker validation} detects whether the same variables
1461
(like \c %1, \c %2) appear both in the source text and in the
1462
translation.
1463
\endlist
1464
1465
To switch validation tests on or off, select \uicontrol Validation or use the
1466
toolbar buttons.
1467
1468
Not accepted strings that fail validation tests are marked with the
1469
\uicontrol {Validation Failures} icon in the \uicontrol Strings view.
1470
Accepted strings are marked with \uicontrol {Accepted/Warnings}.
1471
1472
If you switch validation off and then switch it on later,
1473
\QL rechecks all phrases and marks any that fail validation.
1474
1475
The \uicontrol Warnings view lists the strings that fail the active
1476
validation tests. The first warning is also shown in the status bar
1477
at the bottom of the main window.
1478
1479
\note Only results of \e{active} validation tests are reported.
1480
*/
1481
1482
/*!
1483
\page linguist-translating-multiple-languages.html
1484
\target multiple languages
1485
1486
\previouspage Validating translations
1487
\nextpage AI translation
1488
1489
\title Translating multiple languages simultaneously
1490
1491
You can load and edit multiple translation files simultaneously.
1492
The following screen shot displays \e{German} and \e{French} translation
1493
files loaded.
1494
1495
\image linguist-linguist_2.webp {}
1496
1497
The translation area has color-coded text editing areas for both German and
1498
French. The \uicontrol Context/Label view and the \uicontrol Strings view have
1499
color-coded status columns for each language.
1500
1501
The \uicontrol Items column in the \uicontrol Context/Label view combines the values
1502
for both languages. If the number of translatable strings does not match the
1503
number of accepted strings, either or both languages have strings that you
1504
need to translate or accept. The \uicontrol Strings view shows the translation
1505
acceptance state of each string for each language.
1506
*/
1507
1508
/*!
1509
\page linguist-ai-translation.html
1510
\target ai translation
1511
1512
\previouspage Translating multiple languages simultaneously
1513
\nextpage Developers
1514
1515
\title AI translation
1516
1517
The AI Translation feature lets you automatically generate
1518
translations for the open TS file using a local LLM via Ollama.
1519
1520
To use AI Translation you must first install
1521
\l{https://github.com/jmorganca/ollama}{Ollama} and pull at least one model, for example:
1522
1523
\list
1524
\li \c{ollama pull gpt-oss:20b}
1525
\li \c{ollama pull 7shi/llama-translate:8b-q4_K_M}
1526
\endlist
1527
1528
Then start the Ollama server if not already started:
1529
1530
\code
1531
ollama serve
1532
\endcode
1533
1534
In Linguist, choose \uicontrol{Translation > AI Translation}
1535
to open the AI Translation dialog:
1536
1537
\image linguist-ai-translation-dialog.webp
1538
1539
The dialog provides:
1540
1541
\list
1542
\li \uicontrol {Ollama Server}: the REST endpoint where Ollama listens
1543
(default \c http://127.0.0.1:11434).
1544
\li \uicontrol Model: drop-down of locally installed models.
1545
\li \uicontrol File: the TS file to translate.
1546
\li \uicontrol Filter (optional): limit to strings in a specific group (context or label).
1547
\li \uicontrol Translate button: start the AI translation.
1548
\li \uicontrol {Apply Translations} button: apply the translated items into the TS file.
1549
\endlist
1550
1551
During translation, progress messages appear in the status bar and in the \uicontrol {Translation
1552
Log}. When complete, you can check out the translated texts on the log. Upon clicking on
1553
\uicontrol{Apply Translations}, AI-generated translations are inserted into the TS file.
1554
1555
\note We suggest using one of OpenAI’s open-weight models, e.g., \e{gpt-oss:20b} or other
1556
LLMs trained for translation, e.g., \e{7shi/llama-translate:8b-q4_K_M}. Feel free to
1557
try other models to find the best combination of speed, quality, and resource usage.
1558
*/
1559
1560
/*!
1561
\page linguist-programmers.html
1562
\title Developers
1563
1564
\previouspage AI translation
1565
\nextpage TS File Format
1566
1567
\image front-coding.png
1568
1569
Design your application so that it can be adapted to various languages and
1570
regions without engineering changes.
1571
1572
\list
1573
\li \l{TS file format}
1574
\li \l{Text ID based translations}
1575
\li \l{Meta strings reference}
1576
\li \l{CMake Commands in Qt6 LinguistTools}{CMake commands}
1577
\li \l{Examples}
1578
\endlist
1579
1580
For more information, see also:
1581
\list
1582
\li \l {Internationalization with Qt}
1583
\li \l {Writing Source Code for Translation}
1584
\li \l {Localizing Applications}.
1585
\endlist
1586
1587
You can use Qt Creator wizard templates to create Qt widget-based projects
1588
with translation support. For more information, see
1589
\l {Qt Creator: Creating Projects}.
1590
1591
The following video shows how to internationalize and localize a simple
1592
example application:
1593
1594
\youtube xNIz78IPBu0
1595
*/
1596
1597
/*!
1598
\page linguist-programmers-examples.html
1599
\title Examples
1600
1601
\nextpage Developers
1602
1603
The following examples illustrate how to prepare Qt applications for
1604
translation:
1605
1606
\list
1607
\li \l{hellotr}{Hello tr()} is a C++ application that demonstrates the
1608
creation of a \l QTranslator object. It also shows the simplest use of
1609
the \c tr() function to mark user-visible source text for
1610
translation.
1611
1612
\li \l{arrowpad}{Arrow Pad} is a C++ application that demonstrates how to
1613
make the application load translations depending on the current locale.
1614
It also shows the use of the two-argument form of \c tr() which provides
1615
additional information to the translator.
1616
1617
\li \l{trollprint}{Troll Print} is a C++ application that demonstrates how
1618
to distinguish identical source text in the same context. It also shows
1619
how minimize the translator's work when an application is upgraded.
1620
1621
\li \l{Qt Quick I18N} demonstrates how to internationalize Qt Quick
1622
applications.
1623
\endlist
1624
*/
1625
1626
/*!
1627
\page linguist-ts-file-format.html
1628
\title TS file format
1629
1630
\previouspage Developers
1631
1632
\brief TS file format.
1633
1634
The TS file format used by \QL is described by the
1635
\l{http://www.w3.org/2001/XMLSchema}{XSD} presented below,
1636
which we include for your convenience. Be aware that the format
1637
may change in future Qt releases.
1638
1639
\quotefile ../../../shared/ts.xsd
1640
1641
*/
1642
1643
/*!
1644
\page linguist-id-based-i18n.html
1645
\title Text ID based translations
1646
\ingroup internationalization
1647
1648
1649
\brief Text ID based internationalization provides support for large scale
1650
projects with many target locales and many texts to translate.
1651
1652
The text ID translation mechanism is an \e {industrial strength} system for
1653
internationalization and localization. Each text in the application has a
1654
unique identifier (text ID) that you use in the source code instead of text.
1655
This makes it much easier to manage large numbers of translated texts.
1656
1657
\section1 Internationalizing with text IDs
1658
1659
When using text IDs instead of plain text, the general method of
1660
internationalizing an application is the same but the details are a bit
1661
different:
1662
1663
\list 1
1664
1665
\li The functions and macros for the text-ID-based translation system are
1666
different from the plain-text system. You use the qsTrId() function instead
1667
of qsTr(), the QT_TRID_NOOP() macro instead of QT_TR_NOOP(),
1668
and QT_TRID_N_NOOP() macro instead of QT_TR_N_NOOP()).
1669
1670
\li Use text IDs as user interface strings rather than plain text
1671
strings. For example, \c {qsTrId("id-back-not-front")}
1672
1673
\li You cannot specify a context parameter with a text ID, and therefore
1674
identically spelled words with different meanings need separate
1675
text IDs. For example, \c {qsTrId("id-back-backstep")} differentiates
1676
the back-step \e {Back} from the \c id-back-not-front \e {Back}.
1677
1678
\li Since context names are not allowed for text-ID-based translations,
1679
\QL lists the IDs in a file without context names.
1680
1681
\li The \e {engineering English} text that you see in the user interface for
1682
development builds is indicated with a \c {//%} comment. If you do not
1683
include this, the text ID is shown in the user interface. This is
1684
especially important when you have texts with parameters. The \c {//%}
1685
comment needs to include the parameters indicators in the string. For
1686
example, \c {//% "Number of files: %1"}
1687
1688
\li The \c {//:} comments that provide extra information to the translator
1689
are optional in the plain-text system. However, with the text-ID-based
1690
system, this extra information becomes essential because without it you only
1691
have the text ID and the translator might not be able to make a sensible
1692
translation from that without further context. You can use long descriptive
1693
text IDs and no comments, but comments are often easier to understand.
1694
1695
\endlist
1696
1697
The side-by-side code snippets below show a comparison of text-ID -based and
1698
plain-text-based translations:
1699
1700
\table
1701
\header
1702
\li text-ID-based
1703
\li plain-text-based
1704
\row
1705
\li
1706
\code
1707
Text {
1708
id: backTxt;
1709
//: The back of the object, not the front
1710
//% "Back"
1711
//~ Context Not related to back-stepping
1712
text: qsTrId("id-back-not-front");
1713
}
1714
\endcode
1715
1716
\li
1717
\code
1718
Text {
1719
id: backTxt;
1720
//: The back of the object, not the front
1721
//~ Context Not related to back-stepping
1722
text: qsTr("Back","Not front")
1723
}
1724
\endcode
1725
\endtable
1726
1727
\section1 Localizing with text IDs
1728
1729
Localizing with text IDs follows much the same process as for plain text.
1730
1731
You use the \l{Using lupdate}{lupdate} tool to generate the TS files where
1732
you add the translations. The source values in the translation files will be
1733
text IDs rather than plain text, and therefore you need either descriptive
1734
text IDs or good additional comments, or both to ensure that the translations
1735
are accurate.
1736
1737
The example text-ID-based user interface text from above results in the following
1738
content in the .ts file:
1739
1740
\code
1741
<message id="id-back-not-front">
1742
<source>Back</source>
1743
<extracomment>The back of the object, not the front</extracomment>
1744
<translation type="unfinished"></translation>
1745
<extra-Context>Not related to back-stepping</extra-Context>
1746
</message>
1747
\endcode
1748
1749
If there is no translation available for a given text (which is
1750
generally the case until late in development), the text ID will be shown in
1751
the user interface rather than a proper text. In order to make the application
1752
more usable for testing, you can make \c lrelease use the \e {Engineering English}
1753
source text (from the \c {//%} comments) as the translated text and mark it with
1754
some indicator, such as an exclamation mark (!), so you can see texts that
1755
are not yet translated.
1756
1757
\section2 Grouping ID-Based Translations
1758
1759
You can assign each ID-based translation a \e label to organize
1760
ID-based entries of large projects into smaller groups.
1761
To assign a \e label to an ID-based entry, add a \c{//@} comment
1762
naming the label, for example in C++:
1763
\code cpp
1764
//% "Open file"
1765
//@ FileOperations
1766
qtTrId("msg.open");
1767
\endcode
1768
Or in QML:
1769
\code qml
1770
//% "Open file"
1771
//@ FileOperations
1772
qsTrId("msg.open");
1773
\endcode
1774
When you open the TS file in \l {Qt Linguist}, the ID-based entries with
1775
the same \e label are grouped together, similar to text-based
1776
entries that are grouped by context.
1777
Any item without a \e label appears under \c{<unnamed label>}.
1778
\note Label names have no effect on lookup or uniqueness: IDs remain globally
1779
unique and can still be loaded via \c{qtTrId("msgid")} without referencing a
1780
label. The label tag is used only to improve the translator’s navigation
1781
and does not change runtime behavior.
1782
1783
\section1 CMake configuration
1784
1785
When building with CMake, use the prefix \c qml_ for .ts files.
1786
For example, \c qml_en.ts. In the CMakeLists.txt file, add the
1787
\l qt_add_translations function, where you list the *.ts files
1788
as values of \c TS_FILES, and set the value of RESOURCE_PREFIX to the
1789
URI of the main.qml file for the project followed by /i18n:
1790
1791
\badcode
1792
qt_add_translations(${CMAKE_PROJECT_NAME}
1793
TS_FILES i18n/qml_de_DE.ts i18n/qml_en_US.ts
1794
RESOURCE_PREFIX Main/i18n
1795
)
1796
\endcode
1797
1798
\section1 Advanced use with qmake
1799
1800
For projects that target a large number of locales, you can remove the
1801
TRANSLATIONS info from the .pro file and, instead, manage the translations
1802
with a separate script. The script can call \c lrelease and \c lupdate for each of
1803
the desired targets.
1804
1805
The updates could be scripted something like this:
1806
1807
\code
1808
lupdate -recursive <project-dir> -ts <project-dir>/i18n/myapp-text_en_GB.ts
1809
lupdate -recursive <project-dir> -ts <project-dir>/i18n/myapp-text_en_US.ts
1810
...
1811
\endcode
1812
1813
The generation of the final .qm files could be scripted something like this:
1814
1815
\code
1816
lrelease <project-dir>/i18n/myapp-text_en_GB.ts
1817
lrelease <project-dir>/i18n/myapp-text_en_US.ts
1818
...
1819
\endcode
1820
1821
*/
1822
1823
/*!
1824
\page linguist-meta-strings-reference.html
1825
\title Meta strings reference
1826
\ingroup internationalization
1827
1828
\previouspage Text ID based translations
1829
1830
\brief Reference guide for meta strings used in Qt's translation system.
1831
1832
Meta strings are special comments that provide additional information to
1833
lupdate and \QL for translation processing. They use specific
1834
prefixes to identify their purpose and can be used in C++, QML, and Python code.
1835
1836
\section1 Meta string syntax overview
1837
1838
Meta strings are special comments that use specific prefixes to provide lupdate
1839
with additional information about translations:
1840
1841
\table
1842
\header
1843
\li Meta String
1844
\li Purpose
1845
\li Usage
1846
\row
1847
\li \c{//:}
1848
\li Extra comment for translators
1849
\li Provides context and guidance to help translators
1850
\row
1851
\li \c{//%}
1852
\li Source text (engineering English)
1853
\li Defines display text for ID-based translations during development
1854
\row
1855
\li \c{//@}
1856
\li Label for grouping
1857
\li Organizes ID-based translations into logical groups
1858
\row
1859
\li \c{//~}
1860
\li Extra key-value metadata
1861
\li Stores additional custom information about the translation
1862
\row
1863
\li \c{// TRANSLATOR}
1864
\li Magic comment for context
1865
\li Provides context information about the class or file
1866
\endtable
1867
1868
\note The \c{//=} meta string for message ID mapping is deprecated and should not be used in new code.
1869
1870
\section1 Translator comments (//:)
1871
1872
Use \c{//:} comments to provide additional context and guidance to translators.
1873
These comments appear in the \QL translation interface and help
1874
translators understand the meaning and usage of the text.
1875
1876
\section2 C++ example
1877
\code cpp
1878
//: Button to navigate backwards in the application
1879
tr("Back");
1880
1881
//: This is a file menu item that opens an existing document.
1882
//: Keep translation short to fit in menu.
1883
tr("Open");
1884
\endcode
1885
1886
\section2 QML example
1887
\code qml
1888
Button {
1889
//: Emergency stop button - must be clearly visible
1890
text: qsTr("STOP")
1891
}
1892
\endcode
1893
1894
\section2 Python example
1895
\code python
1896
#: Button to navigate backwards in the application
1897
self.tr("Back")
1898
1899
#: This is a file menu item that opens an existing document.
1900
#: Keep translation short to fit in menu.
1901
self.tr("Open")
1902
\endcode
1903
1904
Multiple translator comments can be used for the same string and will be
1905
concatenated with newlines in the TS file.
1906
1907
\section2 TS file format
1908
1909
Translator comments appear as \c{<extracomment>} elements in the TS file:
1910
1911
\code xml
1912
<message>
1913
<source>Back</source>
1914
<extracomment>Button to navigate backwards in the application</extracomment>
1915
<translation type="unfinished"></translation>
1916
</message>
1917
\endcode
1918
1919
\section1 Source text (//%)
1920
1921
The \c{//%} meta string defines the \e{engineering English} text that appears
1922
in the user interface during development when using ID-based translations.
1923
This is essential for making the application usable before translations
1924
are complete.
1925
1926
\section2 C++ example
1927
\code cpp
1928
//% "Save Document"
1929
qtTrId("file.save");
1930
1931
//% "Found %n items"
1932
qtTrId("search.results", count);
1933
\endcode
1934
1935
\section2 QML example
1936
\code qml
1937
Text {
1938
//% "Welcome to the application"
1939
text: qsTrId("welcome.message")
1940
}
1941
\endcode
1942
1943
\section2 Important notes
1944
\list
1945
\li Include parameter placeholders (%1, %n) in the source text
1946
\li The source text should be production-ready English
1947
\li Without //% comments, the text ID itself appears in the UI
1948
\endlist
1949
1950
\section2 TS file format
1951
1952
Source text appears as the \c{<source>} element:
1953
1954
\code xml
1955
<message id="file.save">
1956
<source>Save Document</source>
1957
<translation type="unfinished"></translation>
1958
</message>
1959
\endcode
1960
1961
\section1 Labels (//@)
1962
1963
Use \c{//@} meta strings to organize ID-based translations into logical
1964
groups or categories within \QL. This is particularly useful
1965
for large projects with many translation strings.
1966
1967
\note The \c{//@} meta string is only intended for ID-based translations
1968
(qtTrId/qsTrId) and should not be used with text-based translations (tr/qsTr).
1969
1970
\section2 C++ example
1971
\code cpp
1972
//% "New Document"
1973
//@ FileOperations
1974
qtTrId("file.new");
1975
1976
//% "Print Document"
1977
//@ FileOperations
1978
qtTrId("file.print");
1979
1980
//% "Connection failed"
1981
//@ NetworkErrors
1982
qtTrId("network.error.connection");
1983
\endcode
1984
1985
\section2 QML example
1986
\code qml
1987
Button {
1988
//% "Login"
1989
//@ Authentication
1990
text: qsTrId("auth.login")
1991
}
1992
\endcode
1993
1994
\note Labels are not applicable to Python translations since Python only supports
1995
text-based translations (self.tr()) and not ID-based translations.
1996
1997
Strings with the same label appear grouped together in \QL,
1998
making it easier for translators to work on related content.
1999
2000
\section2 TS file format
2001
2002
Labels appear as a \c{label} element:
2003
2004
\code xml
2005
<message id="file.new" label="FileOperations">
2006
<source>New Document</source>
2007
<label>FileOperations</label>
2008
<translation type="unfinished"></translation>
2009
</message>
2010
\endcode
2011
2012
\section1 Extra metadata (//~)
2013
2014
The \c{//~} meta string allows you to attach arbitrary key-value metadata
2015
to translations. This can be used for custom processing or translator
2016
guidance.
2017
2018
\section2 Syntax
2019
\code
2020
//~ key value
2021
//~ key "quoted value with spaces"
2022
\endcode
2023
2024
\section2 C++ example
2025
\code cpp
2026
//% "Error"
2027
//: Critical system error dialog
2028
//~ Severity High
2029
//~ MaxLength "20"
2030
//~ Context "Error dialogs"
2031
qtTrId("system.error");
2032
\endcode
2033
2034
\section2 QML example
2035
\code qml
2036
Text {
2037
//% "Loading..."
2038
//~ Context "Progress indicators"
2039
//~ ShowDuration "true"
2040
text: qsTrId("progress.loading")
2041
}
2042
\endcode
2043
2044
\section2 Python example
2045
\code python
2046
#~ Severity High
2047
#~ Context "Error dialogs"
2048
self.tr("Critical system error")
2049
\endcode
2050
2051
\section2 TS file format
2052
2053
Extra metadata appears as \c{<extra-*>} elements in the TS file and can be
2054
processed by custom tools or translation workflows.
2055
2056
\code xml
2057
<message id="system.error">
2058
<source>Error</source>
2059
<comment>Critical system error dialog</comment>
2060
<translation type="unfinished"></translation>
2061
<extra-Severity>High</extra-Severity>
2062
<extra-MaxLength>20</extra-MaxLength>
2063
<extra-Context>Error dialogs</extra-Context>
2064
</message>
2065
\endcode
2066
2067
\section1 TRANSLATOR magic comments
2068
2069
\c{TRANSLATOR} comments provide context information about a class or
2070
source file to help translators understand where translations are used.
2071
2072
\section2 C++ example
2073
\snippet doc_src_linguist-manual.cpp 5
2074
2075
\section2 QML example
2076
\code qml
2077
// TRANSLATOR LoginDialog Login dialog for user authentication
2078
Item {
2079
Text {
2080
text: qsTr("Username")
2081
}
2082
}
2083
\endcode
2084
2085
\section2 Python example
2086
\code python
2087
# TRANSLATOR MainWindow
2088
#
2089
# Main application window containing the primary user interface.
2090
# Keep button labels concise due to space constraints.
2091
#
2092
class MainWindow(QMainWindow):
2093
def setupUi(self):
2094
self.tr("File") # translations for this context
2095
\endcode
2096
2097
\section2 TS file format
2098
2099
TRANSLATOR comment appear as a \c{<message>} elements with empty source text
2100
on the \c{<context>} element:
2101
2102
\code xml
2103
<context>
2104
<name>Main</name>
2105
<message>
2106
<source></source>
2107
<comment>LoginDialog Login dialog for user authentication</comment>
2108
<translation></translation>
2109
</message>
2110
</context>
2111
\endcode
2112
2113
\section1 Combining meta strings
2114
2115
Meta strings can be combined to provide comprehensive translation metadata:
2116
2117
\section2 Complete C++ example
2118
\code cpp
2119
//: File dialog - confirm destructive action
2120
//: This will permanently delete the selected files
2121
//% "Delete Selected Files"
2122
//@ FileOperations
2123
//~ Severity High
2124
//~ RequiresConfirmation "true"
2125
qtTrId("file.delete.confirm");
2126
\endcode
2127
2128
\section2 Complete QML example
2129
\code qml
2130
Text {
2131
//: Shows current connection status to server
2132
//: Updates automatically every few seconds
2133
//% "Connected to server"
2134
//@ NetworkStatus
2135
//~ UpdateFrequency "5000ms"
2136
//~ Color "green"
2137
text: qsTrId("status.connected")
2138
}
2139
\endcode
2140
2141
\section1 Best practices
2142
2143
\list
2144
\li Use translator comments (//:) generously to provide context
2145
\li Always include source text (//%) for ID-based translations
2146
\li Group related translations using labels (//@) in large projects
2147
\li Place meta strings immediately before the translation function call
2148
\li Keep translator comments clear and concise but informative
2149
\li Use consistent naming for labels and extra metadata keys
2150
\endlist
2151
*/
qttools
src
linguist
linguist
doc
src
linguist-manual.qdoc
Generated on
for Qt by
1.14.0