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 example, \c{ } for a non-breaking space).
1561
Otherwise, the
1562
characters appear in their standard visual form. This feature is useful
1563
for instance to maintain the same special characters (such as
1564
emojis, special spaces) in both the source text and its translations.
1565
1566
\section1 Changing the target locale
1567
1568
You can set the locale information explicitly in \uicontrol Edit >
1569
\uicontrol {Translation File Settings}. If the target language and country
1570
are not explicitly set when you open a translation source file, \QL
1571
attempts to deduct them from the translation source file name. This
1572
requires that the translation files adhere to the following file name
1573
convention:
1574
\c appname_language[_country].ts, where:
1575
1576
\list
1577
\li \c language is an ISO 639 language code in lowercase.
1578
\li \c country is an ISO 3166 two-letter country code in uppercase.
1579
\endlist
1580
1581
If this attempt to resolve the target language and country fails, the
1582
\uicontrol {Translation File Settings} window opens.
1583
1584
For example, \c app_de.ts sets the
1585
target language to German, and \c app_de_CH.ts sets the target language to
1586
German and the target country to Switzerland. This also helps loading
1587
translations for the current locale automatically. For more information, see
1588
\l{Enable Translation}.
1589
1590
\image linguist-translationfilesettings.png {Screenshot showing Qt Linguist
1591
settings window with source language POSIX and target language German}
1592
*/
1593
1594
/*!
1595
\page linguist-selecting-context.html
1596
1597
\previouspage Translating strings
1598
\nextpage Selecting strings to translate
1599
1600
\title Selecting context or label to translate
1601
1602
The \uicontrol Context/Label view lists the contexts (\uicontrol {Text based}) or
1603
labels (\uicontrol {ID based}) in which strings to be translated
1604
appear. The text-based translations are grouped into contexts, while ID-based
1605
translations are grouped into labels (see \l{Grouping ID-Based Translations}).
1606
The \uicontrol Context/Label lists the \e groups (that is, context or labels)
1607
based on the selected tab:
1608
\list
1609
\li Upon switching to the \uicontrol{Text-Based} tab,
1610
\uicontrol Context lists the context names in
1611
alphabetical order. Each context is the name of a QML type or a subclass of
1612
QObject.
1613
\li Upon switching to the \uicontrol{ID-Based} tab,
1614
\uicontrol Label lists the label names in
1615
alphabetical order. More info on labels can be found in \l{Grouping ID-Based Translations}.
1616
\endlist
1617
1618
\image linguist-context-view.webp {Context/Label view}
1619
1620
The following icons indicate the current translation state for each group:
1621
1622
\table
1623
\header
1624
\li State
1625
\li Icon
1626
\li Description
1627
1628
\row
1629
\li Accepted/Correct
1630
\li \inlineimage linguist-check-on.png {Check icon}
1631
\li All strings in the group have been translated, and all the
1632
translations passed the \l{Validating Translations}{validation tests}.
1633
1634
\row
1635
\li Accepted/Warnings
1636
\li \inlineimage linguist-check-warning.png {Check warning icon}
1637
\li All strings in the group have been translated or marked as translated,
1638
but at least one translation failed the validation tests.
1639
In the \uicontrol Strings view, you can see which string failed the test.
1640
1641
\row
1642
\li Not Accepted
1643
\li \inlineimage linguist-check-off.png {check off icon}
1644
\li At least one string in the group has not been translated or is not
1645
marked as translated.
1646
1647
\row
1648
\li Obsolete
1649
\li \inlineimage linguist-check-obsolete.png {check obsolete icon}
1650
\li None of the translated strings appears in the group any more. This
1651
usually means the context or label no longer exists in the application.
1652
\endtable
1653
1654
The \uicontrol Items column displays the total number of translatable strings in
1655
the group and the number of translated strings, separated by a slash (/).
1656
If the numbers are equal, all the translatable strings in the group have
1657
translations.
1658
*/
1659
1660
/*!
1661
\page linguist-selecting-strings.html
1662
1663
\previouspage Selecting context or label to translate
1664
\nextpage Viewing strings in context
1665
1666
\title Selecting strings to translate
1667
1668
The \uicontrol Strings view lists all the translatable strings in the
1669
current group (that is, context or label) and their translation acceptance
1670
state. Select a string to view and edit it in the translation area.
1671
1672
\image linguist-strings-view.webp {Strings view}
1673
1674
Click the icon in front of a string to change its translation acceptance
1675
state. A tick mark, green or yellow, means the string has an accepted
1676
translation. A question mark means either that the translation does not
1677
exist or you have not accepted it.
1678
1679
The following icons indicate the current translation state for each string:
1680
1681
\target String Translation States
1682
1683
\table
1684
\header
1685
\li State
1686
\li Icon
1687
\li Description
1688
1689
\row
1690
\li Accepted/Correct
1691
\li \inlineimage linguist-check-on.png {Check icon}
1692
\li The source string has a translation (possibly empty). You accepted
1693
the translation, and it passes all the \l{Validating Translations}
1694
{validation tests}. Click the icon to revoke acceptance of the
1695
translation. The state becomes \uicontrol {Not Accepted} if the string
1696
has a translation or \uicontrol {No Translation} if the translation is
1697
empty. If \c{lupdate} changes the contents of a string, its acceptance
1698
state becomes \uicontrol {Not Accepted}.
1699
1700
\row
1701
\li Accepted/Warnings
1702
\li \inlineimage linguist-check-warning.png {Check warning icon}
1703
\li You accepted the translation, but it does not pass all the validation
1704
tests. The \uicontrol Warnings view shows where it failed. If you click
1705
the icon to revoke acceptance of the translation, the state becomes
1706
\uicontrol {Validation Failures}.
1707
1708
\row
1709
\li Not Accepted
1710
\li \inlineimage linguist-check-off.png {check off icon}
1711
\li The string has a translation that passes all the validation tests, but
1712
you have not yet accepted the translation. Click the icon or press
1713
\key{Ctrl+Enter} to accept the translation. The state becomes
1714
\uicontrol {Accepted/Correct}.
1715
1716
\row
1717
\li No Translation
1718
\li \inlineimage linguist-check-empty.png {check empty icon}
1719
\li The string does not have a translation. If you click the icon to accept
1720
the empty translation, the state becomes \uicontrol {Accepted/Correct}.
1721
1722
\row
1723
\li Validation Failures
1724
\li \inlineimage linguist-danger.png {danger icon}
1725
\li The string has a translation, but the translation does not pass all the
1726
validation tests. The \uicontrol Warnings view shows the validation test
1727
failures. Click on the icon or press \key{Ctrl+Enter} to
1728
accept the translation even with validation failures. The state becomes
1729
\uicontrol {Accepted/Warnings}. Usually, you should fix the causes of the
1730
validation failures. The state will automatically become
1731
\uicontrol {Not Accepted} when you fix all failures.
1732
1733
\row
1734
\li Obsolete
1735
\li \inlineimage linguist-check-obsolete.png {check obsolete icon}
1736
\li The string is obsolete. It is no longer used in the context.
1737
See \l{Using lupdate} for instructions on how to remove obsolete
1738
messages from the file.
1739
1740
\endtable
1741
*/
1742
1743
/*!
1744
\page linguist-viewing-strings-in-context.html
1745
1746
\previouspage Selecting strings to translate
1747
\nextpage Reusing translations
1748
1749
\title Viewing strings in context
1750
1751
If \QL can access the source files containing the translatable strings, the
1752
\uicontrol {Sources and Forms} view shows the source context of the current
1753
string in the \uicontrol Strings view. It highlights the source code line
1754
that contains the current string. If \QL cannot find the source file, it
1755
shows the expected absolute file path.
1756
1757
If the source context shows the wrong source line, the translation file might
1758
be out of sync with the source files. For more information about how to sync
1759
the files, see \l{Using lupdate}.
1760
1761
\QD stores UI forms in special UI files (.ui). \QL attempts to show the
1762
translations in the forms.
1763
*/
1764
1765
/*!
1766
\page linguist-reusing-translations.html
1767
1768
\previouspage Viewing strings in context
1769
\nextpage Validating translations
1770
1771
\title Reusing translations
1772
1773
If the translated text is similar to the source text, select
1774
\uicontrol Translation > \uicontrol {Copy from source text}
1775
(or press \key{Ctrl+B}) to copy the source text into the
1776
translation area.
1777
1778
\e {Phrase books} provide a common set of translations
1779
to help ensure consistency. A phrase book is a set of source phrases, target
1780
(translated) phrases, and optional definitions. Typically, one phrase book
1781
is created per language and family of applications. Phrase books avoid
1782
duplication of effort since they contain translations for a family of
1783
applications.
1784
1785
The \uicontrol {Phrases and guesses} view displays the current string and its
1786
phrase book translations. If the current string is the same as or similar to
1787
a translated string, the view also lists the string and its translation.
1788
1789
To copy a translation from the \uicontrol {Phrases and guesses} view to the
1790
translation area, double-click it or select it and press \key Enter.
1791
1792
\section1 Batch translation
1793
1794
\image linguist-batchtranslation.png {Screenshot showing Qt Linguist batch
1795
translation window with options and phrase book selection}
1796
1797
Use the batch translation feature to automatically translate source
1798
texts that are also in a phrase book. To configure which phrase books to use
1799
in what order during the batch translation process, select \uicontrol Edit >
1800
\uicontrol {Batch Translation}. You can include only entries with no
1801
current translation and mark batch translated entries as \uicontrol Accepted.
1802
1803
\section1 Creating and editing phrase books
1804
1805
Phrase book files are human-readable XML files containing standard phrases
1806
and their translations. \QL creates and update the files. You can use them
1807
for any number of projects and applications.
1808
1809
To create a new phrase book, select \uicontrol Phrases > \uicontrol {New Phrase Book}.
1810
1811
\image linguist-phrasebookdialog.png {Screenshot of Qt Linguist phrase book editor
1812
showing source phrases with German translations}
1813
1814
To open a phrase book, select \uicontrol Phrases > \uicontrol {Open Phrase Book}, and
1815
then select the Qt phrase book file (.qph) to open.
1816
1817
To view and change open phrase books, select \uicontrol Phrases >
1818
\uicontrol {Edit Phrase Book}.
1819
1820
To add a new phrase, select \uicontrol {New Entry} (or press \key {Alt+N}) and
1821
type in a new source phrase, the translation, and an optional definition.
1822
This is useful to distinguish different translations of the same source
1823
phrase.
1824
1825
To add the translation you are working on to the current phrase book, select
1826
\uicontrol Phrases > \uicontrol {Add to Phrase Book} or press \key{Ctrl+T}. If multiple
1827
phrase books are loaded, you have to select one.
1828
1829
If you detect an error in a phrase book entry in the
1830
\uicontrol {Phrases and guesses} view, you can edit by right
1831
clicking it and selecting \uicontrol Edit. After fixing the
1832
error press \key{Enter} to leave the editing mode.
1833
1834
To delete a phrase, select it in the \uicontrol {Source phrase} list, and then
1835
select \uicontrol {Remove Entry}.
1836
1837
To print an open phrase book, select \uicontrol Phrases >
1838
\uicontrol {Print Phrase Book}.
1839
*/
1840
1841
/*!
1842
\page linguist-validating-translations.html
1843
1844
\previouspage Reusing translations
1845
\nextpage Translating multiple languages simultaneously
1846
1847
\title Validating translations
1848
1849
\QL provides the following validation tests for translations:
1850
1851
\list
1852
\li \e {Accelerator validation} detects translated phrases
1853
that do not have an ampersand when the source phrase does and vice
1854
versa.
1855
\li \e {Punctuation validation} detects differences in the
1856
terminating punctuation between source and translated phrases when
1857
this may be significant. For example, warns if the source phrase
1858
ends with an ellipsis, exclamation mark or question mark, and the
1859
translated phrase does not, and vice versa.
1860
\li \e {Phrases validation} detects source phrases that are
1861
also in the phrase book but whose translation differs from that
1862
in the phrase book.
1863
\li \e {Place marker validation} detects whether the same variables
1864
(like \c %1, \c %2) appear both in the source text and in the
1865
translation.
1866
\endlist
1867
1868
To switch validation tests on or off, select \uicontrol Validation or use the
1869
toolbar buttons.
1870
1871
Not accepted strings that fail validation tests are marked with the
1872
\uicontrol {Validation Failures} icon in the \uicontrol Strings view.
1873
Accepted strings are marked with \uicontrol {Accepted/Warnings}.
1874
1875
If you switch validation off and then switch it on later,
1876
\QL rechecks all phrases and marks any that fail validation.
1877
1878
The \uicontrol Warnings view lists the strings that fail the active
1879
validation tests. The first warning is also shown in the status bar
1880
at the bottom of the main window.
1881
1882
\note Only results of \e{active} validation tests are reported.
1883
*/
1884
1885
/*!
1886
\page linguist-translating-multiple-languages.html
1887
\target multiple languages
1888
1889
\previouspage Validating translations
1890
\nextpage AI translation
1891
1892
\title Translating multiple languages simultaneously
1893
1894
You can load and edit multiple translation files simultaneously.
1895
The following screen shot displays \e{German} and \e{French} translation
1896
files loaded.
1897
1898
\image linguist-linguist_2.webp {}
1899
1900
The translation area has color-coded text editing areas for both German and
1901
French. The \uicontrol Context/Label view and the \uicontrol Strings view have
1902
color-coded status columns for each language.
1903
1904
The \uicontrol Items column in the \uicontrol Context/Label view combines the values
1905
for both languages. If the number of translatable strings does not match the
1906
number of accepted strings, either or both languages have strings that you
1907
need to translate or accept. The \uicontrol Strings view shows the translation
1908
acceptance state of each string for each language.
1909
*/
1910
1911
/*!
1912
\page linguist-ai-translation.html
1913
\target ai translation
1914
1915
\previouspage Translating multiple languages simultaneously
1916
\nextpage Developers
1917
1918
\title AI translation
1919
1920
The AI Translation feature lets you automatically generate translations for the
1921
open TS file using large language models (LLMs). You can use either a local LLM
1922
server (such as \l{https://ollama.com}{Ollama},
1923
\l{https://lmstudio.ai}{LM Studio}, or
1924
\l{https://github.com/ggml-org/llama.cpp}{llama.cpp}) or cloud-based APIs that
1925
support the OpenAI-compatible REST protocol (such as OpenAI, Groq, or Anthropic).
1926
1927
Qt Linguist supports two API modes:
1928
\list
1929
\li \e{Ollama} - Ollama's native REST API. Use this when running
1930
\l{https://ollama.com}{Ollama} locally.
1931
\li \e{OpenAI Compatible} - The standard OpenAI REST API format. Use this for:
1932
\list
1933
\li Local servers: LM Studio, llama.cpp, or Ollama (which also supports
1934
OpenAI-compatible mode)
1935
\li Cloud providers: OpenAI, Groq, DeepSeek, and others
1936
\endlist
1937
\endlist
1938
1939
\section1 Setting up a local LLM server
1940
1941
To use AI Translation with a local server, install one of the following and
1942
download at least one model:
1943
1944
\list
1945
\li \l{https://ollama.com}{Ollama} - Easy to use, manages models automatically
1946
\li \l{https://lmstudio.ai}{LM Studio} - GUI application with model browser
1947
\li \l{https://github.com/ggml-org/llama.cpp}{llama.cpp} - Lightweight,
1948
runs GGUF models directly
1949
\endlist
1950
1951
\note Running LLMs locally requires sufficient memory depending on the model
1952
size and quantization level. Refer to your LLM server's documentation for
1953
specific requirements, for example
1954
\l{https://lmstudio.ai/docs/app/system-requirements}{LM Studio System Requirements}.
1955
1956
For Ollama, pull a model using the command line:
1957
1958
\code
1959
ollama pull qwen3:14b
1960
ollama serve
1961
\endcode
1962
1963
For LM Studio, download models through the application's interface and start
1964
the local server:
1965
1966
\code
1967
lms server start
1968
\endcode
1969
1970
For llama.cpp, you can either use one of the built-in model presets:
1971
1972
\code
1973
llama-server --fim-qwen-7b-default
1974
\endcode
1975
1976
Or download a GGUF model file and start the server manually:
1977
1978
\code
1979
llama-server -m model.gguf --port 8080
1980
\endcode
1981
1982
\section1 Using cloud APIs
1983
1984
To use cloud-based translation services, select \e{OpenAI Compatible} as the
1985
API type, enter the provider's API endpoint URL, and provide your API key.
1986
1987
Enter only the base URL without the \c{/v1} path suffix. For example, for
1988
\l{https://openrouter.ai}{OpenRouter} use \c{https://openrouter.ai/api}.
1989
Consult your provider's documentation for the correct endpoint URL.
1990
1991
\section1 Using the AI Translation dialog
1992
1993
In Linguist, choose \uicontrol{Tools > AI Translation} to open the
1994
AI Translation dialog:
1995
1996
The \c Configuration part of the dialog provides:
1997
1998
\list
1999
\li \uicontrol {API Type}: choose \e{Ollama} for local Ollama servers using
2000
Ollama's native API, or \e{OpenAI Compatible} for LM Studio, llama.cpp,
2001
cloud APIs, or Ollama in OpenAI-compatible mode.
2002
\li \uicontrol {Server URL}: the base URL where the server listens. Do not
2003
include the \c{/v1} path suffix.
2004
Default: \c http://localhost:11434 for Ollama,
2005
\c http://localhost:8080 for OpenAI Compatible.
2006
\li \uicontrol {API Key}: authentication key for cloud APIs (optional for
2007
local servers).
2008
\li \uicontrol Model: drop-down list of available models.
2009
\li \uicontrol Context: optional application context to improve translation
2010
accuracy (e.g., "medical software", "video game", "financial application").
2011
\endlist
2012
2013
\image translationDialog1.webp {Screenshot of Qt Linguist AI translation dialog - Configuration}
2014
2015
The \c Selection part of the dialog provides:
2016
\list
2017
\li \uicontrol File: the TS file to translate.
2018
\li \uicontrol Filter: limit translation to specific groups (contexts or labels).
2019
\li \uicontrol Translate: start the AI translation.
2020
\endlist
2021
2022
\image translationDialog2.webp {Screenshot of Qt Linguist AI translation dialog - Selection}
2023
2024
The \c Progress part of the dialog provides:
2025
\list
2026
\li A stop button to stop the translation progress
2027
\li \uicontrol {Apply Translations}: apply the translated items into the TS file.
2028
\endlist
2029
2030
\image translationDialog3.webp {Screenshot of Qt Linguist AI translation dialog - Progress}
2031
2032
During translation, progress messages appear in the \uicontrol{Translation Log}.
2033
When complete, review the translated texts in the log. Click
2034
\uicontrol{Apply Translations} to insert the AI-generated translations into
2035
the TS file.
2036
2037
\section1 Security considerations
2038
2039
AI translation sends data over the network to the server you configure. Before
2040
using it, consider the following:
2041
2042
\list
2043
\li \b{Keep confidential strings off remote servers.} Qt Linguist sends the
2044
source strings to translate, and any \uicontrol Context you provide, to
2045
the configured server. Use only a server you trust, and prefer a local
2046
LLM server.
2047
\li \b{Review AI-generated translations before applying them.} Qt Linguist
2048
inserts the server's translations as-is. Treat them as untrusted
2049
content and review them in the \uicontrol{Translation Log} before
2050
choosing \uicontrol{Apply Translations}, as they may contain
2051
unexpected markup or format specifiers.
2052
\li \b{Prefer HTTPS for remote servers.} Qt Linguist sends the API key as a
2053
bearer token in the request. If the \uicontrol{Server URL} uses \c http
2054
instead of \c https, anyone on the network path can read the key and
2055
source text in cleartext. Use \c https for any server that is not
2056
running on your local machine.
2057
\endlist
2058
2059
\section1 Recommended models
2060
2061
The following models are recommended for translation tasks, balancing quality,
2062
speed, and resource usage. These models can be found on:
2063
2064
\list
2065
\li \l{https://ollama.com/library}{Ollama} - search by model name
2066
(e.g., \c{ollama pull qwen3:14b})
2067
\li \l{https://lmstudio.ai}{LM Studio} - search in the model browser
2068
\li \l{https://huggingface.co}{Hugging Face} - download GGUF files for llama.cpp
2069
\endlist
2070
2071
\table
2072
\header
2073
\li Model
2074
\li Size
2075
\li Notes
2076
\row
2077
\li Mistral Small 24B
2078
\li 14 GB
2079
\li High translation quality with strong multilingual support.
2080
Requires >16 GB VRAM for optimal performance.
2081
\row
2082
\li Qwen3 14B
2083
\li 9 GB
2084
\li Balance of quality and resource usage. Supports 100+ languages.
2085
\row
2086
\li Qwen3 30B
2087
\li 19 GB
2088
\li High-quality translations. Uses MoE architecture for efficient inference.
2089
\row
2090
\li Qwen2.5 14B
2091
\li 9 GB
2092
\li Strong multilingual support for 29+ languages including CJK languages.
2093
\row
2094
\li Gemma 3 12B
2095
\li 8 GB
2096
\li Supports 140+ languages. Good for resource-constrained systems.
2097
\row
2098
\li 7shi/llama-translate 8B
2099
\li 5 GB
2100
\li Specialized translation model for English, French, Chinese, and Japanese.
2101
Lightweight option for limited hardware. Available on Ollama only.
2102
\endtable
2103
2104
For systems with limited resources, smaller variants like Qwen3 8B (5 GB) or
2105
Qwen2.5 7B (5 GB) provide reasonable translation quality while requiring
2106
less memory.
2107
2108
\note Translation quality varies by language pair and model. Test different
2109
models to find the best combination of speed, quality, and resource usage for
2110
your specific translation needs.
2111
*/
2112
2113
/*!
2114
\page linguist-programmers.html
2115
\title Developers
2116
2117
\previouspage AI translation
2118
\nextpage TS File Format
2119
2120
\image front-coding.png {Illustration showing a code}
2121
2122
Design your application so that it can be adapted to various languages and
2123
regions without engineering changes.
2124
2125
\list
2126
\li \l{TS file format}
2127
\li \l{Text ID based translations}
2128
\li \l{Meta strings reference}
2129
\li \l{CMake Commands in Qt6 LinguistTools}{CMake commands}
2130
\li \l{Examples}
2131
\endlist
2132
2133
For more information, see also:
2134
\list
2135
\li \l {Internationalization with Qt}
2136
\li \l {Writing Source Code for Translation}
2137
\li \l {Localizing Applications}.
2138
\endlist
2139
2140
You can use Qt Creator wizard templates to create Qt widget-based projects
2141
with translation support. For more information, see
2142
\l {Qt Creator: Creating Projects}.
2143
2144
The following video shows how to internationalize and localize a simple
2145
example application:
2146
2147
\youtube xNIz78IPBu0
2148
*/
2149
2150
/*!
2151
\page linguist-programmers-examples.html
2152
\title Examples
2153
2154
\nextpage Developers
2155
2156
The following examples illustrate how to prepare Qt applications for
2157
translation:
2158
2159
\list
2160
\li \l{arrowpad}{Arrow Pad} is a C++ application that demonstrates how to
2161
make the application load translations depending on the current locale.
2162
It also shows the use of the two-argument form of \c tr() which provides
2163
additional information to the translator.
2164
2165
\li \l{trollprint}{Troll Print} is a C++ application that demonstrates how
2166
to distinguish identical source text in the same context. It also shows
2167
how minimize the translator's work when an application is upgraded.
2168
\endlist
2169
*/
2170
2171
/*!
2172
\page linguist-ts-file-format.html
2173
\title TS file format
2174
2175
\previouspage Developers
2176
2177
\brief TS file format.
2178
2179
The TS file format used by \QL is described by the
2180
\l{http://www.w3.org/2001/XMLSchema}{XSD} presented below,
2181
which we include for your convenience. Be aware that the format
2182
may change in future Qt releases.
2183
2184
\quotefile ../../../shared/ts.xsd
2185
2186
*/
2187
2188
/*!
2189
\page linguist-id-based-i18n.html
2190
\title Text ID based translations
2191
\ingroup internationalization
2192
2193
2194
\brief Text ID based internationalization provides support for large scale
2195
projects with many target locales and many texts to translate.
2196
2197
The text ID translation mechanism is an \e {industrial strength} system for
2198
internationalization and localization. Each text in the application has a
2199
unique identifier (text ID) that you use in the source code instead of text.
2200
This makes it much easier to manage large numbers of translated texts.
2201
2202
\section1 Internationalizing with text IDs
2203
2204
When using text IDs instead of plain text, the general method of
2205
internationalizing an application is the same but the details are a bit
2206
different:
2207
2208
\list 1
2209
2210
\li The functions and macros for the text-ID-based translation system are
2211
different from the plain-text system. You use the qsTrId() function instead
2212
of qsTr(), the QT_TRID_NOOP() macro instead of QT_TR_NOOP(),
2213
and QT_TRID_N_NOOP() macro instead of QT_TR_N_NOOP()).
2214
2215
\li Use text IDs as user interface strings rather than plain text
2216
strings. For example, \c {qsTrId("id-back-not-front")}
2217
2218
\li You cannot specify a context parameter with a text ID, and therefore
2219
identically spelled words with different meanings need separate
2220
text IDs. For example, \c {qsTrId("id-back-backstep")} differentiates
2221
the back-step \e {Back} from the \c id-back-not-front \e {Back}.
2222
2223
\li Since context names are not allowed for text-ID-based translations,
2224
\QL lists the IDs in a file without context names.
2225
2226
\li The \e {engineering English} text that you see in the user interface for
2227
development builds is indicated with a \c {//%} comment. If you do not
2228
include this, the text ID is shown in the user interface. This is
2229
especially important when you have texts with parameters. The \c {//%}
2230
comment needs to include the parameters indicators in the string. For
2231
example, \c {//% "Number of files: %1"}
2232
2233
\li The \c {//:} comments that provide extra information to the translator
2234
are optional in the plain-text system. However, with the text-ID-based
2235
system, this extra information becomes essential because without it you only
2236
have the text ID and the translator might not be able to make a sensible
2237
translation from that without further context. You can use long descriptive
2238
text IDs and no comments, but comments are often easier to understand.
2239
2240
\endlist
2241
2242
The side-by-side code snippets below show a comparison of text-ID -based and
2243
plain-text-based translations:
2244
2245
\table
2246
\header
2247
\li text-ID-based
2248
\li plain-text-based
2249
\row
2250
\li
2251
\code
2252
Text {
2253
id: backTxt;
2254
//: The back of the object, not the front
2255
//% "Back"
2256
//~ Context Not related to back-stepping
2257
text: qsTrId("id-back-not-front");
2258
}
2259
\endcode
2260
2261
\li
2262
\code
2263
Text {
2264
id: backTxt;
2265
//: The back of the object, not the front
2266
//~ Context Not related to back-stepping
2267
text: qsTr("Back","Not front")
2268
}
2269
\endcode
2270
\endtable
2271
2272
\section1 Localizing with text IDs
2273
2274
Localizing with text IDs follows much the same process as for plain text.
2275
2276
You use the \l{Using lupdate}{lupdate} tool to generate the TS files where
2277
you add the translations. The source values in the translation files will be
2278
text IDs rather than plain text, and therefore you need either descriptive
2279
text IDs or good additional comments, or both to ensure that the translations
2280
are accurate.
2281
2282
The example text-ID-based user interface text from above results in the following
2283
content in the .ts file:
2284
2285
\code
2286
<message id="id-back-not-front">
2287
<source>Back</source>
2288
<extracomment>The back of the object, not the front</extracomment>
2289
<translation type="unfinished"></translation>
2290
<extra-Context>Not related to back-stepping</extra-Context>
2291
</message>
2292
\endcode
2293
2294
If there is no translation available for a given text (which is
2295
generally the case until late in development), the text ID will be shown in
2296
the user interface rather than a proper text. In order to make the application
2297
more usable for testing, you can make \c lrelease use the \e {Engineering English}
2298
source text (from the \c {//%} comments) as the translated text and mark it with
2299
some indicator, such as an exclamation mark (!), so you can see texts that
2300
are not yet translated.
2301
2302
\section2 Grouping ID-Based Translations
2303
2304
You can assign each ID-based translation a \e label to organize
2305
ID-based entries of large projects into smaller groups.
2306
To assign a \e label to an ID-based entry, add a \c{//@} comment
2307
naming the label, for example in C++:
2308
\code cpp
2309
//% "Open file"
2310
//@ FileOperations
2311
qtTrId("msg.open");
2312
\endcode
2313
Or in QML:
2314
\code qml
2315
//% "Open file"
2316
//@ FileOperations
2317
qsTrId("msg.open");
2318
\endcode
2319
When you open the TS file in \l {Qt Linguist}, the ID-based entries with
2320
the same \e label are grouped together, similar to text-based
2321
entries that are grouped by context.
2322
Any item without a \e label appears under \c{<unnamed label>}.
2323
\note Label names have no effect on lookup or uniqueness: IDs remain globally
2324
unique and can still be loaded via \c{qtTrId("msgid")} without referencing a
2325
label. The label tag is used only to improve the translator's navigation
2326
and does not change runtime behavior.
2327
2328
\section3 Automatic Label Generation
2329
2330
Instead of manually specifying label names, you can use placeholders
2331
to automatically generate labels based on the code structure:
2332
2333
\list
2334
\li \c{//@ <context>} - Automatically uses the full context (namespace::class)
2335
\li \c{//@ <class>} - Automatically uses only the class name (without namespaces)
2336
\li \c{//@ <file>} - Automatically uses the source filename
2337
\endlist
2338
2339
\section4 Combining Placeholders
2340
2341
Placeholders can be combined with custom text to create more descriptive labels:
2342
2343
\list
2344
\li \c{//@ <file>:<class>} - Combines filename and class: \c{filehandler.cpp:FileHandler}
2345
\li \c{//@ <context>_customSuffix} - Adds suffix: \c{MyApp::FileHandler_customSuffix}
2346
\li \c{//@ module_<file>_<class>-label} - Custom prefix and suffix: \c{module_filehandler.cpp_FileHandler-label}
2347
\li \c{//@ <context>:<file>} - Context with file: \c{MyApp::FileHandler:filehandler.cpp}
2348
\endlist
2349
2350
For example, in C++:
2351
\code cpp
2352
namespace MyApp {
2353
class FileHandler : QObject {
2354
Q_OBJECT
2355
void open() {
2356
//% "Open file"
2357
//@ <context>
2358
qtTrId("msg.open"); // Label: MyApp::FileHandler
2359
2360
//% "Save file"
2361
//@ <class>
2362
qtTrId("msg.save"); // Label: FileHandler
2363
2364
//% "Export"
2365
//@ <file>
2366
qtTrId("msg.export"); // Label: filehandler.cpp
2367
}
2368
};
2369
}
2370
\endcode
2371
2372
Or in QML:
2373
\code qml
2374
Item {
2375
id: myComponent
2376
Component.onCompleted: {
2377
//% "Loading"
2378
//@ <context>
2379
qsTrId("msg.loading") // Label: <component-name>
2380
2381
//% "Ready"
2382
//@ <file>
2383
qsTrId("msg.ready") // Label: main.qml
2384
2385
//% "Initialized"
2386
//@ <file>:<context>-state
2387
qsTrId("msg.init") // Label: main.qml:<component-name>-state
2388
}
2389
}
2390
\endcode
2391
2392
Auto labels are particularly useful in large projects where manually
2393
managing label names across many files can be tedious. They ensure
2394
consistent grouping based on code structure and give hints to translators
2395
about where the translation will be used.
2396
2397
\note When using \c{<class>} in C++ code outside any classes, a warning
2398
will be issued and \c{<unnamed>} will be used in the generated label.
2399
2400
\note Using \c{<class>} in QML will generate a
2401
warning and \c{<unnamed>} will be used, since QML
2402
components are not classes. Use \c{<context>} instead to get the
2403
component name, or \c{<file>} to get the QML filename.
2404
2405
\note Auto labels only work with ID-based translations (\c qtTrId, \c qsTrId).
2406
Using auto labels with text-based translations (\c tr, \c qsTr) will generate
2407
a warning and the label will be ignored.
2408
2409
\section1 CMake configuration
2410
2411
When building with CMake, use the prefix \c qml_ for .ts files.
2412
For example, \c qml_en.ts. In the CMakeLists.txt file, add the
2413
\l qt_add_translations function, where you list the *.ts files
2414
as values of \c TS_FILES, and set the value of RESOURCE_PREFIX to the
2415
URI of the main.qml file for the project followed by /i18n:
2416
2417
\badcode
2418
qt_add_translations(${CMAKE_PROJECT_NAME}
2419
TS_FILES i18n/qml_de_DE.ts i18n/qml_en_US.ts
2420
RESOURCE_PREFIX Main/i18n
2421
)
2422
\endcode
2423
2424
\section1 Advanced use with qmake
2425
2426
For projects that target a large number of locales, you can remove the
2427
TRANSLATIONS info from the .pro file and, instead, manage the translations
2428
with a separate script. The script can call \c lrelease and \c lupdate for each of
2429
the desired targets.
2430
2431
The updates could be scripted something like this:
2432
2433
\code
2434
lupdate -recursive <project-dir> -ts <project-dir>/i18n/myapp-text_en_GB.ts
2435
lupdate -recursive <project-dir> -ts <project-dir>/i18n/myapp-text_en_US.ts
2436
...
2437
\endcode
2438
2439
The generation of the final .qm files could be scripted something like this:
2440
2441
\code
2442
lrelease <project-dir>/i18n/myapp-text_en_GB.ts
2443
lrelease <project-dir>/i18n/myapp-text_en_US.ts
2444
...
2445
\endcode
2446
2447
*/
2448
2449
/*!
2450
\page linguist-meta-strings-reference.html
2451
\title Meta strings reference
2452
\ingroup internationalization
2453
2454
\previouspage Text ID based translations
2455
2456
\brief Reference guide for meta strings used in Qt's translation system.
2457
2458
Meta strings are special comments that provide additional information to
2459
lupdate and \QL for translation processing. They use specific
2460
prefixes to identify their purpose and can be used in C++, QML, and Python code.
2461
2462
\section1 Meta string syntax overview
2463
2464
Meta strings are special comments that use specific prefixes to provide lupdate
2465
with additional information about translations:
2466
2467
\table
2468
\header
2469
\li Meta String
2470
\li Purpose
2471
\li Usage
2472
\row
2473
\li \c{//:}
2474
\li Extra comment for translators
2475
\li Provides context and guidance to help translators
2476
\row
2477
\li \c{//%}
2478
\li Source text (engineering English)
2479
\li Defines display text for ID-based translations during development
2480
\row
2481
\li \c{//@}
2482
\li Label for grouping
2483
\li Organizes ID-based translations into logical groups
2484
\row
2485
\li \c{//~}
2486
\li Extra key-value metadata
2487
\li Stores additional custom information about the translation
2488
\row
2489
\li \c{// TRANSLATOR}
2490
\li Magic comment for context
2491
\li Provides context information about the class or file
2492
\endtable
2493
2494
\note The \c{//=} meta string for message ID mapping is deprecated and should not be used in new code.
2495
2496
\section1 Translator comments (//:)
2497
2498
Use \c{//:} comments to provide additional context and guidance to translators.
2499
These comments appear in the \QL translation interface and help
2500
translators understand the meaning and usage of the text.
2501
2502
\section2 C++ example
2503
\code cpp
2504
//: Button to navigate backwards in the application
2505
tr("Back");
2506
2507
//: This is a file menu item that opens an existing document.
2508
//: Keep translation short to fit in menu.
2509
tr("Open");
2510
\endcode
2511
2512
\section2 QML example
2513
\code qml
2514
Button {
2515
//: Emergency stop button - must be clearly visible
2516
text: qsTr("STOP")
2517
}
2518
\endcode
2519
2520
\section2 Python example
2521
\code python
2522
#: Button to navigate backwards in the application
2523
self.tr("Back")
2524
2525
#: This is a file menu item that opens an existing document.
2526
#: Keep translation short to fit in menu.
2527
self.tr("Open")
2528
\endcode
2529
2530
Multiple translator comments can be used for the same string and will be
2531
concatenated with newlines in the TS file.
2532
2533
\section2 TS file format
2534
2535
Translator comments appear as \c{<extracomment>} elements in the TS file:
2536
2537
\code xml
2538
<message>
2539
<source>Back</source>
2540
<extracomment>Button to navigate backwards in the application</extracomment>
2541
<translation type="unfinished"></translation>
2542
</message>
2543
\endcode
2544
2545
\section1 Source text (//%)
2546
2547
The \c{//%} meta string defines the \e{engineering English} text that appears
2548
in the user interface during development when using ID-based translations.
2549
This is essential for making the application usable before translations
2550
are complete.
2551
2552
\section2 C++ example
2553
\code cpp
2554
//% "Save Document"
2555
qtTrId("file.save");
2556
2557
//% "Found %n items"
2558
qtTrId("search.results", count);
2559
\endcode
2560
2561
\section2 QML example
2562
\code qml
2563
Text {
2564
//% "Welcome to the application"
2565
text: qsTrId("welcome.message")
2566
}
2567
\endcode
2568
2569
\section2 Important notes
2570
\list
2571
\li Include parameter placeholders (%1, %n) in the source text
2572
\li The source text should be production-ready English
2573
\li Without //% comments, the text ID itself appears in the UI
2574
\endlist
2575
2576
\section2 TS file format
2577
2578
Source text appears as the \c{<source>} element:
2579
2580
\code xml
2581
<message id="file.save">
2582
<source>Save Document</source>
2583
<translation type="unfinished"></translation>
2584
</message>
2585
\endcode
2586
2587
\section1 Labels (//@)
2588
2589
Use \c{//@} meta strings to organize ID-based translations into logical
2590
groups or categories within \QL. This is particularly useful
2591
for large projects with many translation strings.
2592
2593
\note The \c{//@} meta string is only intended for ID-based translations
2594
(qtTrId/qsTrId) and should not be used with text-based translations (tr/qsTr).
2595
2596
\section2 C++ example
2597
\code cpp
2598
//% "New Document"
2599
//@ FileOperations
2600
qtTrId("file.new");
2601
2602
//% "Print Document"
2603
//@ FileOperations
2604
qtTrId("file.print");
2605
2606
//% "Connection failed"
2607
//@ NetworkErrors
2608
qtTrId("network.error.connection");
2609
\endcode
2610
2611
\section2 QML example
2612
\code qml
2613
Button {
2614
//% "Login"
2615
//@ Authentication
2616
text: qsTrId("auth.login")
2617
}
2618
\endcode
2619
2620
\note Labels are not applicable to Python translations since Python only supports
2621
text-based translations (self.tr()) and not ID-based translations.
2622
2623
Strings with the same label appear grouped together in \QL,
2624
making it easier for translators to work on related content.
2625
2626
For automatic label generation using placeholders like \c{<context>}, \c{<class>},
2627
\c{<file>}, and their combinations, see \l{Automatic Label Generation}.
2628
2629
\section2 TS file format
2630
2631
Labels appear as a \c{label} element:
2632
2633
\code xml
2634
<message id="file.new" label="FileOperations">
2635
<source>New Document</source>
2636
<label>FileOperations</label>
2637
<translation type="unfinished"></translation>
2638
</message>
2639
\endcode
2640
2641
\section1 Extra metadata (//~)
2642
2643
The \c{//~} meta string allows you to attach arbitrary key-value metadata
2644
to translations. This can be used for custom processing or translator
2645
guidance.
2646
2647
\section2 Syntax
2648
\code
2649
//~ key value
2650
//~ key "quoted value with spaces"
2651
\endcode
2652
2653
\section2 C++ example
2654
\code cpp
2655
//% "Error"
2656
//: Critical system error dialog
2657
//~ Severity High
2658
//~ MaxLength "20"
2659
//~ Context "Error dialogs"
2660
qtTrId("system.error");
2661
\endcode
2662
2663
\section2 QML example
2664
\code qml
2665
Text {
2666
//% "Loading..."
2667
//~ Context "Progress indicators"
2668
//~ ShowDuration "true"
2669
text: qsTrId("progress.loading")
2670
}
2671
\endcode
2672
2673
\section2 Python example
2674
\code python
2675
#~ Severity High
2676
#~ Context "Error dialogs"
2677
self.tr("Critical system error")
2678
\endcode
2679
2680
\section2 TS file format
2681
2682
Extra metadata appears as \c{<extra-*>} elements in the TS file and can be
2683
processed by custom tools or translation workflows.
2684
2685
\code xml
2686
<message id="system.error">
2687
<source>Error</source>
2688
<comment>Critical system error dialog</comment>
2689
<translation type="unfinished"></translation>
2690
<extra-Severity>High</extra-Severity>
2691
<extra-MaxLength>20</extra-MaxLength>
2692
<extra-Context>Error dialogs</extra-Context>
2693
</message>
2694
\endcode
2695
2696
\section2 Recognized extra keys
2697
2698
While any key can be used with \c{//~}, the \c no-wrap flag within
2699
\c po-flags is recognized by \c lconvert. See \l{PO format-specific options}.
2700
2701
\section1 TRANSLATOR magic comments
2702
2703
\c{TRANSLATOR} comments provide context information about a class or
2704
source file to help translators understand where translations are used.
2705
2706
\section2 C++ example
2707
\snippet doc_src_linguist-manual.cpp 5
2708
2709
\section2 QML example
2710
\code qml
2711
// TRANSLATOR LoginDialog Login dialog for user authentication
2712
Item {
2713
Text {
2714
text: qsTr("Username")
2715
}
2716
}
2717
\endcode
2718
2719
\section2 Python example
2720
\code python
2721
# TRANSLATOR MainWindow
2722
#
2723
# Main application window containing the primary user interface.
2724
# Keep button labels concise due to space constraints.
2725
#
2726
class MainWindow(QMainWindow):
2727
def setupUi(self):
2728
self.tr("File") # translations for this context
2729
\endcode
2730
2731
\section2 TS file format
2732
2733
TRANSLATOR comment appear as a \c{<message>} elements with empty source text
2734
on the \c{<context>} element:
2735
2736
\code xml
2737
<context>
2738
<name>Main</name>
2739
<message>
2740
<source></source>
2741
<comment>LoginDialog Login dialog for user authentication</comment>
2742
<translation></translation>
2743
</message>
2744
</context>
2745
\endcode
2746
2747
\section1 Combining meta strings
2748
2749
Meta strings can be combined to provide comprehensive translation metadata:
2750
2751
\section2 Complete C++ example
2752
\code cpp
2753
//: File dialog - confirm destructive action
2754
//: This will permanently delete the selected files
2755
//% "Delete Selected Files"
2756
//@ FileOperations
2757
//~ Severity High
2758
//~ RequiresConfirmation "true"
2759
qtTrId("file.delete.confirm");
2760
\endcode
2761
2762
\section2 Complete QML example
2763
\code qml
2764
Text {
2765
//: Shows current connection status to server
2766
//: Updates automatically every few seconds
2767
//% "Connected to server"
2768
//@ NetworkStatus
2769
//~ UpdateFrequency "5000ms"
2770
//~ Color "green"
2771
text: qsTrId("status.connected")
2772
}
2773
\endcode
2774
2775
\section1 Best practices
2776
2777
\list
2778
\li Use translator comments (//:) generously to provide context
2779
\li Always include source text (//%) for ID-based translations
2780
\li Group related translations using labels (//@) in large projects
2781
\li Place meta strings immediately before the translation function call
2782
\li Keep translator comments clear and concise but informative
2783
\li Use consistent naming for labels and extra metadata keys
2784
\endlist
2785
*/
qttools
src
linguist
linguist
doc
src
linguist-manual.qdoc
Generated on
for Qt by
1.16.1