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
1001The \c lcheck command line tool validates Qt \c {TS} translation files and
1002produces a human-readable report. It is part of the Qt Linguist toolchain
1003and is intended for batch or CI usage to catch common localization issues
1004early. By default, \c lcheck runs a set of checks and returns a non-zero
1005exit code if at least one enabled check fails.
1006
1007The 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
1020Each check can be disabled individually using command line options.
1021
1022\section1 lcheck syntax
1023
1024\badcode
1025lcheck [options] -o report-output-file ts-file
1026lcheck [options] ts-file
1027\endcode
1028
1029Where:
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
1038To view the latest help, enter:
1039
1040\badcode
1041lcheck -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
1080makes \c lcheck suitable for use in CI pipelines.
1081
1082\section1 Examples
1083
1084\section2 Write a report to a file
1085
1086\badcode
1087lcheck -o lcheck_report.txt translations/myapp_de.ts
1088\endcode
1089
1090\section2 Disable selected checks
1091
1092The following command runs all checks except accelerator and punctuation:
1093
1094\badcode
1095lcheck -no-accelerator -no-punctuation translations/myapp_de.ts
1096\endcode
1097
1098\section2 Check finished translations as well
1099
1100\badcode
1101lcheck -check-finished translations/myapp_de.ts
1102\endcode
1103
1104\section2 Use lcheck in a CI step
1105
1106\badcode
1107lcheck translations/myapp_de.ts && echo "Translations OK" || echo "Issues found"
1108\endcode
1109
1110\section2 Using lcheck with CMake
1111
1112To call \c lcheck when configuring or building your CMake project, load
1113the \c Qt6LinguistTools package and use \c {$<TARGET_FILE:Qt6::lcheck>}
1114to locate the \c lcheck executable.
1115
1116The 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
1120find_package(Qt6 REQUIRED COMPONENTS LinguistTools)
1121
1122add_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
1131add_custom_target(check_translations
1132 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/lcheck_report.txt"
1133)
1134\endcode
1135
1136\section2 Using lcheck with qmake
1137
1138You can run \c lcheck directly on a TS file without specifying a project file:
1139
1140\badcode
1141lcheck 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
1153The \c ltext2id command line tool converts a project that uses
1154text-based translations to use ID-based translations. It scans the
1155project tree, updates source code to call the ID-based translation
1156APIs, and adjusts the related \c {TS} files accordingly. In the case
1157of 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
1161running \c ltext2id. The tool modifies source files and \c {TS} files
1162in place.
1163
1164For best results, include both the sources and the \c {TS} files in
1165the project root you pass to the tool so that updates stay consistent
1166between code and translations.
1167
1168\section1 ltext2id syntax
1169
1170\badcode
1171ltext2id [options] [project-root]
1172\endcode
1173
1174Where:
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
1181To view the latest help, enter:
1182
1183\badcode
1184ltext2id -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
1227Run the tool at the project root. The source code and \c {TS} files
1228under that directory are updated in place.
1229
1230\badcode
1231ltext2id path/to/project
1232\endcode
1233
1234\section2 Generate only ID suggestions (no code changes)
1235
1236Use \c -only-meta-id to inject meta-string ID suggestions without
1237rewriting calls to the ID-based API. As a result, the translation
1238calls are annotated by '//~ meta-id <id>' (cpp) meta string
1239specifying the suggested IDs (meta ID).
1240
1241\badcode
1242ltext2id -only-meta-id path/to/project
1243\endcode
1244
1245\section2 Disable label generation
1246
1247Prevent label generation if you do not want contexts mirrored as
1248labels in Qt Linguist:
1249
1250\badcode
1251ltext2id -no-labels path/to/project
1252\endcode
1253
1254\section2 Avoid auto-generated IDs
1255
1256Skip auto-generation for calls missing meta IDs, i.e., IDs
1257already specified using the meta string '//~ meta-id <id>' (cpp):
1258
1259\badcode
1260ltext2id -no-auto-id path/to/project
1261\endcode
1262
1263\section2 Work with UTF-16 source files
1264
1265If your sources are UTF-16 encoded, enable the option:
1266
1267\badcode
1268ltext2id -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,
1274when it encounters an unrecoverable error while transforming files).
1275Inspect the in-place source annotations marked with
1276\c {//ltext2id error:} to fix the remaining issues.
1277*/
1278
1279/*!
1280 \page linguist-translators.html
1281
1282 \previouspage Using ltext2id
1283 \nextpage Qt Linguist user interface
1284
1285 \title Translators
1286
1287 \image front-ui.png {UI illustration showing Start buttons, toggle,
1288 controls, and a circular selector on a dark screen}
1289
1290 \QL is a tool for translating strings in Qt applications. Once you have
1291 installed Qt, you can start \QL in the same way as any other application on
1292 the development host.
1293
1294 \note You can obtain an installer for \QL only (without the entire Qt SDK)
1295 from \l {https://download.qt.io/linguist_releases/}. The installer is
1296 available for Windows, and works with Qt 6.
1297
1298 To address issues that arise from the subtleties and complexities of
1299 human language, translators and developers may need to:
1300
1301 \list
1302 \li Translate a single phrase into several different forms depending on
1303 context. For example, \e open in English might become \e{\ouml}\e{ffnen},
1304 \e {open file}, or \e aufbauen, \e {open internet connection}, in German.
1305
1306 \li Change the mnemonic characters in keyboard shortcuts without introducing
1307 conflicts. For example, \c \&Quit in English becomes \e Avslutt in
1308 Norwegian, which does not contain the letter \e Q. You cannot use a
1309 letter that is already in use unless you change several shortcuts.
1310
1311 \li Rephrase strings that contain variables. For example, you might need to
1312 place the variables in a different order when you translate the string
1313 \e {The 25 files selected will take 63 seconds to process}, where the
1314 two numbers are inserted programmatically at runtime.
1315 \endlist
1316
1317 For more information about how to use \QL to translate applications, see:
1318
1319 \list
1320 \li \l {Qt Linguist user interface}
1321 \li \l {Translating strings}
1322 \li \l {Selecting context or label to translate}
1323 \li \l {Selecting strings to translate}
1324 \li \l {Viewing strings in context}
1325 \li \l {Reusing translations}
1326 \li \l {Validating translations}
1327 \li \l {Translating multiple languages simultaneously}
1328 \li \l {AI translation}
1329 \endlist
1330*/
1331
1332/*!
1333 \page linguist-ui.html
1334
1335 \previouspage Translators
1336 \nextpage Translating strings
1337
1338 \title Qt Linguist user interface
1339
1340 The \QL main window contains a menu bar and the following views:
1341
1342 \list
1343
1344 \li \uicontrol Context/Label (\key F6) lists translation contexts or labels.
1345
1346 \li \uicontrol Strings (\key F7) lists translatable strings in the
1347 selected context.
1348
1349 \li \uicontrol {Sources and Forms} (\key F9) displays the selected
1350 string in the source code.
1351
1352 \li Translation area displays the selected string and enables you to
1353 enter a translation for it.
1354
1355 \li \uicontrol {Phrases and guesses} (\key F10) lists possible
1356 translations for the current string.
1357
1358 \li \uicontrol Warnings (\key F8) lists translated strings that fail
1359 validation tests.
1360
1361 \endlist
1362
1363 \image linguist.webp {Qt Linguist UI}
1364
1365 The translation area (1) is always visible. To show or hide the other views,
1366 select \uicontrol View > \uicontrol Views, or use keyboard shortcuts.
1367 You can drag the views by their title bars and arrange them around the
1368 translation area or even outside the main window.
1369*/
1370
1371/*!
1372 \page linguist-translating-strings.html
1373
1374 \previouspage Qt Linguist user interface
1375 \nextpage Selecting context or label to translate
1376
1377 \title Translating strings
1378
1379 Open translation source (TS) files in \QL for translation. TS files are
1380 human-readable XML files containing source phrases and their translations.
1381 TS files are usually created and updated by \c lupdate. If you do not have
1382 a TS file, see \l {Creating translation files} to learn how to generate one.
1383
1384 You can use \QL also to translate files in the international XML
1385 Localization Interchange File Format (XLIFF) that are generated by other
1386 programs. However, for standard Qt projects, only the TS file format is
1387 used. Only XLIFF versions 1.1 and 1.2 are currently supported.
1388
1389 \QL displays the target language in the translation area, and adapts the
1390 number of input fields for plural forms accordingly. When you open several
1391 TS files to translate simultaneously, the \uicontrol Translator and
1392 \uicontrol {Translator comment} fields are displayed for each language.
1393 For more information about setting the location information, see
1394 \l{Changing the target locale}.
1395
1396 If the developer provides a disambiguating comment, you can see it in the
1397 \uicontrol {Developer comments} field.
1398
1399 To translate strings:
1400 \list 1
1401
1402 \li Select \uicontrol File > \uicontrol Open to load a TS file.
1403
1404 \li Select a context in the \uicontrol Context view to display translatable
1405 strings in the \uicontrol Strings view.
1406
1407 \image linguist-ui.webp {}
1408
1409 \li Select a string to display it in the \uicontrol {Source text} field
1410 in the translation area. The whitespace within the source text is
1411 visualized.
1412
1413 \li Enter the translation of the current string in the \uicontrol Translation
1414 field.
1415
1416 Double-click an existing translation in the
1417 \uicontrol {Phrases and guesses} field to use it as the translation
1418 for the current string. \QL reads the phrases from phrase books and
1419 bases the guesses on existing translations of similar phrases in the
1420 TS file.
1421
1422 \li Optionally, enter a comment for other translators in the
1423 \uicontrol {Translator comment} field.
1424
1425 \li To accept the translation, press \key {Ctrl+Enter}, select
1426 \inlineimage linguist-doneandnext.png {Icon}
1427 , or click the icon to the left of the selected source string in the
1428 string list.
1429
1430 \li Select \uicontrol File > \uicontrol Save to save your work.
1431
1432 \endlist
1433
1434 Repeat this process until all strings in the string list are marked with
1435 \inlineimage linguist-check-on.png {Check icon}
1436 (\uicontrol {Accepted/Correct}) or
1437 \inlineimage linguist-check-warning.png {Check warning icon}
1438 (\uicontrol {Accepted/Warnings}). Then select the next context and continue.
1439
1440 To view the number of words and characters in the source text and in the
1441 translated text, select \uicontrol View > \uicontrol Statistics.
1442
1443 Select \uicontrol File > \uicontrol Release to create a QM
1444 file with the same base name as the current translation source file.
1445 The \c lrelease tool performs the same function on \e all of an
1446 application's translation source files.
1447
1448 To print the translation source and the translations, select \uicontrol File >
1449 \uicontrol Print.
1450
1451 To quit \QL, select \uicontrol File > \uicontrol Exit.
1452
1453 \section1 Moving between translatable strings
1454
1455 To move to the next unfinished translation, select
1456 \inlineimage nextunfinished.png {Icon}
1457 (\uicontrol {Next Unfinished}) or press \key{Ctrl+J}.
1458
1459 To move to the next source text, select \inlineimage next.png {next icon}
1460 , press \key{Ctrl+Shift+J}, or select \uicontrol Translation >
1461 \uicontrol Next.
1462
1463 \section1 Phrases that require multiple translations depending on context
1464
1465 The same phrase may occur in more than one context without conflict. When
1466 you reach another occurrence of a translated phrase, \QL provides
1467 the previous translation as a possible translation in the
1468 \uicontrol {Phrases and guesses} view.
1469
1470 If a phrase occurs more than once within a particular context, it appears
1471 only once in the \uicontrol Context view, and the translation is applied
1472 to every occurrence within the context. If the same phrase means different
1473 things within the same context, the developer must provide a comment for
1474 each occurrence of the phrase. The duplicate phrases appear in the
1475 \uicontrol Context view. The developer's comments appear in the translation
1476 area on a light blue background.
1477
1478 \section1 Changing keyboard shortcuts
1479
1480 A keyboard shortcut is a key combination that performs an action.
1481
1482 \section2 Alt key shortcuts
1483
1484 In menu item and button text, a \e mnemonic character (marked by underlining)
1485 indicates that pressing \key Alt or \key Ctrl with the underlined character
1486 performs the same action as clicking the menu item or pressing the button.
1487
1488 For example, applications often use \e F as the mnemonic character in the
1489 \uicontrol {File} menu, so you can either click the menu item or press
1490 \key {Alt+F} to open the menu. The mnemonic character in the translatable
1491 string is prefixed with an ampersand: \c {\&File}. The translation for the
1492 string should also have an ampersand in it, preferably in front of the same
1493 character.
1494
1495 You can determine the meaning of an \key Alt key shortcut from the phrase
1496 that contains the ampersand. You can use another mnemonic character if the
1497 translated phrase does not contain the current one or if it is used in
1498 the translation of some other shortcut in the context. Some key shortcuts,
1499 usually those on the menu bar, may apply in other contexts.
1500
1501 \section2 Ctrl key shortcuts
1502
1503 \key Ctrl key shortcuts can exist independently of any visual control.
1504 Typically, they invoke actions in menus that would require multiple
1505 keystrokes or mouse clicks or actions that do not appear in any menu
1506 or on any button. For example, the \uicontrol {File} menu might contain a
1507 \uicontrol {\underline{N}ew Ctrl+N} item that you can invoke by pressing
1508 \key {Ctrl+N} even when the \uicontrol {File} menu is closed.
1509
1510 Each \key Ctrl key shortcut appears in the \uicontrol Strings view
1511 as a separate string. For example, \key{Ctrl+Enter}. Since
1512 the string does not have a context to give it meaning, such as
1513 the context of the phrase in which an \key Alt key shortcut appears,
1514 you must rely on the developer to include a \l{QObject::tr()}
1515 {disambiguation comment} to explain the action the \key Ctrl key
1516 shortcut performs. The comment appears under \uicontrol {Developer comments}
1517 in the translation area below the \uicontrol {Source text} field.
1518
1519 Ideally, you can copy translations for \key Ctrl key shortcuts by
1520 selecting \uicontrol Translation > \uicontrol {Copy from source text}.
1521 However, if the character does not make sense in the target language,
1522 change it. Whichever character (alpha or digit) you choose, use the form
1523 \key {Ctrl+} followed by the upper case character. Qt automatically displays
1524 the correct name at runtime. As with \key Alt key shortcuts, if you change
1525 the character, make sure that it does not conflict with any other
1526 \key Ctrl key shortcut.
1527
1528 \note Do not translate the \key Alt, \key Ctrl or \key Shift parts of
1529 the shortcuts, as Qt recognizes them and automatically translates them
1530 for supported languages.
1531
1532 \section1 Handling numbered arguments and plural forms
1533
1534 A numbered argument is a placeholder that will be replaced with text at
1535 runtime. It appears in a source string as a percent sign followed by
1536 a digit. For example, in the \c{After processing file %1, file %2
1537 is next in line} string, \c{%1} and \c{%2} are numbered arguments that
1538 are replaced with the first and second file names at runtime. The
1539 same numbered arguments must appear in the translation, but not
1540 necessarily in the same order. A German translation of the string
1541 might reverse the phrases, for example \c{Datei %2 wird bearbeitet, wenn
1542 Datei %1 fertig ist}. Both numbered arguments appear in the
1543 translation, but in the reverse order. A numbered argument is always
1544 replaced by the same text in the translations, regardless of the position
1545 in the argument sequence in the source string.
1546
1547 The use of numbered arguments is often accompanied by the use of
1548 plural forms in the source text. In many languages, the form of the
1549 text will depend on the value shown, and more than one translation
1550 is required. If the developers have marked up the source text in
1551 correct way, fields for each of the possible plural forms will be
1552 available in the translation area. For more information, see
1553 \l{Writing Source Code for Translation}.
1554
1555 \section1 Handling numeric character references (NCR) in translations
1556
1557 Select \uicontrol {NCR mode} to toggle the representation of
1558 numeric character references in both the source text and the translation
1559 fields. When selected, special characters in the text are displayed as their
1560 corresponding NCRs (for examlple, &#160; for a non-breaking space). Otherwise, the
1561 characters appear in their standard visual form. This feature is useful
1562 for instance to maintain the same special characters (such as
1563 emojis, special spaces) in both the source text and its translations.
1564
1565 \section1 Changing the target locale
1566
1567 You can set the locale information explicitly in \uicontrol Edit >
1568 \uicontrol {Translation File Settings}. If the target language and country
1569 are not explicitly set when you open a translation source file, \QL
1570 attempts to deduct them from the translation source file name. This
1571 requires that the translation files adhere to the following file name
1572 convention:
1573 \c appname_language[_country].ts, where:
1574
1575 \list
1576 \li \c language is an ISO 639 language code in lowercase.
1577 \li \c country is an ISO 3166 two-letter country code in uppercase.
1578 \endlist
1579
1580 If this attempt to resolve the target language and country fails, the
1581 \uicontrol {Translation File Settings} window opens.
1582
1583 For example, \c app_de.ts sets the
1584 target language to German, and \c app_de_CH.ts sets the target language to
1585 German and the target country to Switzerland. This also helps loading
1586 translations for the current locale automatically. For more information, see
1587 \l{Enable Translation}.
1588
1589 \image linguist-translationfilesettings.png {Screenshot showing Qt Linguist
1590 settings window with source language POSIX and target language German}
1591*/
1592
1593/*!
1594 \page linguist-selecting-context.html
1595
1596 \previouspage Translating strings
1597 \nextpage Selecting strings to translate
1598
1599 \title Selecting context or label to translate
1600
1601 The \uicontrol Context/Label view lists the contexts (\uicontrol {Text based}) or
1602 labels (\uicontrol {ID based}) in which strings to be translated
1603 appear. The text-based translations are grouped into contexts, while ID-based
1604 translations are grouped into labels (see \l{Grouping ID-Based Translations}).
1605 The \uicontrol Context/Label lists the \e groups (that is, context or labels)
1606 based on the selected tab:
1607 \list
1608 \li Upon switching to the \uicontrol{Text-Based} tab,
1609 \uicontrol Context lists the context names in
1610 alphabetical order. Each context is the name of a QML type or a subclass of
1611 QObject.
1612 \li Upon switching to the \uicontrol{ID-Based} tab,
1613 \uicontrol Label lists the label names in
1614 alphabetical order. More info on labels can be found in \l{Grouping ID-Based Translations}.
1615 \endlist
1616
1617 \image linguist-context-view.webp {Context/Label view}
1618
1619 The following icons indicate the current translation state for each group:
1620
1621 \table
1622 \header
1623 \li State
1624 \li Icon
1625 \li Description
1626
1627 \row
1628 \li Accepted/Correct
1629 \li \inlineimage linguist-check-on.png {Check icon}
1630 \li All strings in the group have been translated, and all the
1631 translations passed the \l{Validating Translations}{validation tests}.
1632
1633 \row
1634 \li Accepted/Warnings
1635 \li \inlineimage linguist-check-warning.png {Check warning icon}
1636 \li All strings in the group have been translated or marked as translated,
1637 but at least one translation failed the validation tests.
1638 In the \uicontrol Strings view, you can see which string failed the test.
1639
1640 \row
1641 \li Not Accepted
1642 \li \inlineimage linguist-check-off.png {check off icon}
1643 \li At least one string in the group has not been translated or is not
1644 marked as translated.
1645
1646 \row
1647 \li Obsolete
1648 \li \inlineimage linguist-check-obsolete.png {check obsolete icon}
1649 \li None of the translated strings appears in the group any more. This
1650 usually means the context or label no longer exists in the application.
1651 \endtable
1652
1653 The \uicontrol Items column displays the total number of translatable strings in
1654 the group and the number of translated strings, separated by a slash (/).
1655 If the numbers are equal, all the translatable strings in the group have
1656 translations.
1657*/
1658
1659/*!
1660 \page linguist-selecting-strings.html
1661
1662 \previouspage Selecting context or label to translate
1663 \nextpage Viewing strings in context
1664
1665 \title Selecting strings to translate
1666
1667 The \uicontrol Strings view lists all the translatable strings in the
1668 current group (that is, context or label) and their translation acceptance
1669 state. Select a string to view and edit it in the translation area.
1670
1671 \image linguist-strings-view.webp {Strings view}
1672
1673 Click the icon in front of a string to change its translation acceptance
1674 state. A tick mark, green or yellow, means the string has an accepted
1675 translation. A question mark means either that the translation does not
1676 exist or you have not accepted it.
1677
1678 The following icons indicate the current translation state for each string:
1679
1680 \target String Translation States
1681
1682 \table
1683 \header
1684 \li State
1685 \li Icon
1686 \li Description
1687
1688 \row
1689 \li Accepted/Correct
1690 \li \inlineimage linguist-check-on.png {Check icon}
1691 \li The source string has a translation (possibly empty). You accepted
1692 the translation, and it passes all the \l{Validating Translations}
1693 {validation tests}. Click the icon to revoke acceptance of the
1694 translation. The state becomes \uicontrol {Not Accepted} if the string
1695 has a translation or \uicontrol {No Translation} if the translation is
1696 empty. If \c{lupdate} changes the contents of a string, its acceptance
1697 state becomes \uicontrol {Not Accepted}.
1698
1699 \row
1700 \li Accepted/Warnings
1701 \li \inlineimage linguist-check-warning.png {Check warning icon}
1702 \li You accepted the translation, but it does not pass all the validation
1703 tests. The \uicontrol Warnings view shows where it failed. If you click
1704 the icon to revoke acceptance of the translation, the state becomes
1705 \uicontrol {Validation Failures}.
1706
1707 \row
1708 \li Not Accepted
1709 \li \inlineimage linguist-check-off.png {check off icon}
1710 \li The string has a translation that passes all the validation tests, but
1711 you have not yet accepted the translation. Click the icon or press
1712 \key{Ctrl+Enter} to accept the translation. The state becomes
1713 \uicontrol {Accepted/Correct}.
1714
1715 \row
1716 \li No Translation
1717 \li \inlineimage linguist-check-empty.png {check empty icon}
1718 \li The string does not have a translation. If you click the icon to accept
1719 the empty translation, the state becomes \uicontrol {Accepted/Correct}.
1720
1721 \row
1722 \li Validation Failures
1723 \li \inlineimage linguist-danger.png {danger icon}
1724 \li The string has a translation, but the translation does not pass all the
1725 validation tests. The \uicontrol Warnings view shows the validation test
1726 failures. Click on the icon or press \key{Ctrl+Enter} to
1727 accept the translation even with validation failures. The state becomes
1728 \uicontrol {Accepted/Warnings}. Usually, you should fix the causes of the
1729 validation failures. The state will automatically become
1730 \uicontrol {Not Accepted} when you fix all failures.
1731
1732 \row
1733 \li Obsolete
1734 \li \inlineimage linguist-check-obsolete.png {check obsolete icon}
1735 \li The string is obsolete. It is no longer used in the context.
1736 See \l{Using lupdate} for instructions on how to remove obsolete
1737 messages from the file.
1738
1739 \endtable
1740*/
1741
1742/*!
1743 \page linguist-viewing-strings-in-context.html
1744
1745 \previouspage Selecting strings to translate
1746 \nextpage Reusing translations
1747
1748 \title Viewing strings in context
1749
1750 If \QL can access the source files containing the translatable strings, the
1751 \uicontrol {Sources and Forms} view shows the source context of the current
1752 string in the \uicontrol Strings view. It highlights the source code line
1753 that contains the current string. If \QL cannot find the source file, it
1754 shows the expected absolute file path.
1755
1756 If the source context shows the wrong source line, the translation file might
1757 be out of sync with the source files. For more information about how to sync
1758 the files, see \l{Using lupdate}.
1759
1760 \QD stores UI forms in special UI files (.ui). \QL attempts to show the
1761 translations in the forms.
1762*/
1763
1764/*!
1765 \page linguist-reusing-translations.html
1766
1767 \previouspage Viewing strings in context
1768 \nextpage Validating translations
1769
1770 \title Reusing translations
1771
1772 If the translated text is similar to the source text, select
1773 \uicontrol Translation > \uicontrol {Copy from source text}
1774 (or press \key{Ctrl+B}) to copy the source text into the
1775 translation area.
1776
1777 \e {Phrase books} provide a common set of translations
1778 to help ensure consistency. A phrase book is a set of source phrases, target
1779 (translated) phrases, and optional definitions. Typically, one phrase book
1780 is created per language and family of applications. Phrase books avoid
1781 duplication of effort since they contain translations for a family of
1782 applications.
1783
1784 The \uicontrol {Phrases and guesses} view displays the current string and its
1785 phrase book translations. If the current string is the same as or similar to
1786 a translated string, the view also lists the string and its translation.
1787
1788 To copy a translation from the \uicontrol {Phrases and guesses} view to the
1789 translation area, double-click it or select it and press \key Enter.
1790
1791 \section1 Batch translation
1792
1793 \image linguist-batchtranslation.png {Screenshot showing Qt Linguist batch
1794 translation window with options and phrase book selection}
1795
1796 Use the batch translation feature to automatically translate source
1797 texts that are also in a phrase book. To configure which phrase books to use
1798 in what order during the batch translation process, select \uicontrol Edit >
1799 \uicontrol {Batch Translation}. You can include only entries with no
1800 current translation and mark batch translated entries as \uicontrol Accepted.
1801
1802 \section1 Creating and editing phrase books
1803
1804 Phrase book files are human-readable XML files containing standard phrases
1805 and their translations. \QL creates and update the files. You can use them
1806 for any number of projects and applications.
1807
1808 To create a new phrase book, select \uicontrol Phrases > \uicontrol {New Phrase Book}.
1809
1810 \image linguist-phrasebookdialog.png {Screenshot of Qt Linguist phrase book editor
1811 showing source phrases with German translations}
1812
1813 To open a phrase book, select \uicontrol Phrases > \uicontrol {Open Phrase Book}, and
1814 then select the Qt phrase book file (.qph) to open.
1815
1816 To view and change open phrase books, select \uicontrol Phrases >
1817 \uicontrol {Edit Phrase Book}.
1818
1819 To add a new phrase, select \uicontrol {New Entry} (or press \key {Alt+N}) and
1820 type in a new source phrase, the translation, and an optional definition.
1821 This is useful to distinguish different translations of the same source
1822 phrase.
1823
1824 To add the translation you are working on to the current phrase book, select
1825 \uicontrol Phrases > \uicontrol {Add to Phrase Book} or press \key{Ctrl+T}. If multiple
1826 phrase books are loaded, you have to select one.
1827
1828 If you detect an error in a phrase book entry in the
1829 \uicontrol {Phrases and guesses} view, you can edit by right
1830 clicking it and selecting \uicontrol Edit. After fixing the
1831 error press \key{Enter} to leave the editing mode.
1832
1833 To delete a phrase, select it in the \uicontrol {Source phrase} list, and then
1834 select \uicontrol {Remove Entry}.
1835
1836 To print an open phrase book, select \uicontrol Phrases >
1837 \uicontrol {Print Phrase Book}.
1838*/
1839
1840/*!
1841 \page linguist-validating-translations.html
1842
1843 \previouspage Reusing translations
1844 \nextpage Translating multiple languages simultaneously
1845
1846 \title Validating translations
1847
1848 \QL provides the following validation tests for translations:
1849
1850 \list
1851 \li \e {Accelerator validation} detects translated phrases
1852 that do not have an ampersand when the source phrase does and vice
1853 versa.
1854 \li \e {Punctuation validation} detects differences in the
1855 terminating punctuation between source and translated phrases when
1856 this may be significant. For example, warns if the source phrase
1857 ends with an ellipsis, exclamation mark or question mark, and the
1858 translated phrase does not, and vice versa.
1859 \li \e {Phrases validation} detects source phrases that are
1860 also in the phrase book but whose translation differs from that
1861 in the phrase book.
1862 \li \e {Place marker validation} detects whether the same variables
1863 (like \c %1, \c %2) appear both in the source text and in the
1864 translation.
1865 \endlist
1866
1867 To switch validation tests on or off, select \uicontrol Validation or use the
1868 toolbar buttons.
1869
1870 Not accepted strings that fail validation tests are marked with the
1871 \uicontrol {Validation Failures} icon in the \uicontrol Strings view.
1872 Accepted strings are marked with \uicontrol {Accepted/Warnings}.
1873
1874 If you switch validation off and then switch it on later,
1875 \QL rechecks all phrases and marks any that fail validation.
1876
1877 The \uicontrol Warnings view lists the strings that fail the active
1878 validation tests. The first warning is also shown in the status bar
1879 at the bottom of the main window.
1880
1881 \note Only results of \e{active} validation tests are reported.
1882*/
1883
1884/*!
1885 \page linguist-translating-multiple-languages.html
1886 \target multiple languages
1887
1888 \previouspage Validating translations
1889 \nextpage AI translation
1890
1891 \title Translating multiple languages simultaneously
1892
1893 You can load and edit multiple translation files simultaneously.
1894 The following screen shot displays \e{German} and \e{French} translation
1895 files loaded.
1896
1897 \image linguist-linguist_2.webp {}
1898
1899 The translation area has color-coded text editing areas for both German and
1900 French. The \uicontrol Context/Label view and the \uicontrol Strings view have
1901 color-coded status columns for each language.
1902
1903 The \uicontrol Items column in the \uicontrol Context/Label view combines the values
1904 for both languages. If the number of translatable strings does not match the
1905 number of accepted strings, either or both languages have strings that you
1906 need to translate or accept. The \uicontrol Strings view shows the translation
1907 acceptance state of each string for each language.
1908*/
1909
1910/*!
1911 \page linguist-ai-translation.html
1912 \target ai translation
1913
1914 \previouspage Translating multiple languages simultaneously
1915 \nextpage Developers
1916
1917 \title AI translation
1918
1919 The AI Translation feature lets you automatically generate translations for the
1920 open TS file using large language models (LLMs). You can use either a local LLM
1921 server (such as \l{https://ollama.com}{Ollama},
1922 \l{https://lmstudio.ai}{LM Studio}, or
1923 \l{https://github.com/ggml-org/llama.cpp}{llama.cpp}) or cloud-based APIs that
1924 support the OpenAI-compatible REST protocol (such as OpenAI, Groq, or Anthropic).
1925
1926 \section1 Setting up a local LLM server
1927
1928 To use AI Translation with a local server, install one of the following and
1929 download at least one model:
1930
1931 \list
1932 \li \l{https://ollama.com}{Ollama} - Easy to use, manages models automatically
1933 \li \l{https://lmstudio.ai}{LM Studio} - GUI application with model browser
1934 \li \l{https://github.com/ggml-org/llama.cpp}{llama.cpp} - Lightweight,
1935 runs GGUF models directly
1936 \endlist
1937
1938 For Ollama, pull a model using the command line:
1939
1940 \code
1941 ollama pull qwen3:14b
1942 ollama serve
1943 \endcode
1944
1945 For LM Studio, download models through the application's interface and start
1946 the local server:
1947
1948 \code
1949 lms server start
1950 \endcode
1951
1952 For llama.cpp, you can either use one of the built-in model presets:
1953
1954 \code
1955 llama-server --fim-qwen-7b-default
1956 \endcode
1957
1958 Or download a GGUF model file and start the server manually:
1959
1960 \code
1961 llama-server -m model.gguf --port 8080
1962 \endcode
1963
1964 \section1 Using cloud APIs
1965
1966 To use cloud-based translation services, select \e{OpenAI Compatible} as the
1967 API type, enter the provider's API endpoint URL, and provide your API key.
1968 The API key field accepts authentication tokens for services like OpenAI,
1969 Anthropic, Groq, and other OpenAI-compatible providers.
1970
1971 \section1 Using the AI Translation dialog
1972
1973 In Linguist, choose \uicontrol{Tools > AI Translation} to open the
1974 AI Translation dialog:
1975
1976 The \c Configuration part of the dialog provides:
1977
1978 \list
1979 \li \uicontrol {API Type}: choose between \e{Ollama} for local Ollama servers
1980 or \e{OpenAI Compatible} for LM Studio, llama.cpp, or cloud APIs.
1981 \li \uicontrol {Server URL}: the REST endpoint where the server listens
1982 (default \c http://localhost:11434 for Ollama,
1983 \c http://localhost:8080 for OpenAI Compatible).
1984 \li \uicontrol {API Key}: authentication key for cloud APIs (optional for
1985 local servers).
1986 \li \uicontrol Model: drop-down list of available models.
1987 \li \uicontrol Context: optional application context to improve translation
1988 accuracy (e.g., "medical software", "video game", "financial application").
1989 \endlist
1990
1991 \image translationDialog1.webp {Screenshot of Qt Linguist AI translation dialog - Configuration}
1992
1993 The \c Selection part of the dialog provides:
1994 \list
1995 \li \uicontrol File: the TS file to translate.
1996 \li \uicontrol Filter: limit translation to specific groups (contexts or labels).
1997 \li \uicontrol Translate: start the AI translation.
1998 \endlist
1999
2000 \image translationDialog2.webp {Screenshot of Qt Linguist AI translation dialog - Selection}
2001
2002 The \c Progress part of the dialog provides:
2003 \list
2004 \li A stop button to stop the translation progress
2005 \li \uicontrol {Apply Translations}: apply the translated items into the TS file.
2006 \endlist
2007
2008 \image translationDialog3.webp {Screenshot of Qt Linguist AI translation dialog - Progress}
2009
2010 During translation, progress messages appear in the \uicontrol{Translation Log}.
2011 When complete, review the translated texts in the log. Click
2012 \uicontrol{Apply Translations} to insert the AI-generated translations into
2013 the TS file.
2014
2015 \section1 Recommended models
2016
2017 The following models are recommended for translation tasks, balancing quality,
2018 speed, and resource usage. These models can be found on:
2019
2020 \list
2021 \li \l{https://ollama.com/library}{Ollama} - search by model name
2022 (e.g., \c{ollama pull qwen3:14b})
2023 \li \l{https://lmstudio.ai}{LM Studio} - search in the model browser
2024 \li \l{https://huggingface.co}{Hugging Face} - download GGUF files for llama.cpp
2025 \endlist
2026
2027 \table
2028 \header
2029 \li Model
2030 \li Size
2031 \li Notes
2032 \row
2033 \li Mistral Small 24B
2034 \li 14 GB
2035 \li High translation quality with strong multilingual support.
2036 Requires >16 GB VRAM for optimal performance.
2037 \row
2038 \li Qwen3 14B
2039 \li 9 GB
2040 \li Balance of quality and resource usage. Supports 100+ languages.
2041 \row
2042 \li Qwen3 30B
2043 \li 19 GB
2044 \li High-quality translations. Uses MoE architecture for efficient inference.
2045 \row
2046 \li Qwen2.5 14B
2047 \li 9 GB
2048 \li Strong multilingual support for 29+ languages including CJK languages.
2049 \row
2050 \li Gemma 3 12B
2051 \li 8 GB
2052 \li Supports 140+ languages. Good for resource-constrained systems.
2053 \row
2054 \li 7shi/llama-translate 8B
2055 \li 5 GB
2056 \li Specialized translation model for English, French, Chinese, and Japanese.
2057 Lightweight option for limited hardware. Available on Ollama only.
2058 \endtable
2059
2060 For systems with limited resources, smaller variants like Qwen3 8B (5 GB) or
2061 Qwen2.5 7B (5 GB) provide reasonable translation quality while requiring
2062 less memory.
2063
2064 \note Translation quality varies by language pair and model. Test different
2065 models to find the best combination of speed, quality, and resource usage for
2066 your specific translation needs.
2067*/
2068
2069/*!
2070 \page linguist-programmers.html
2071 \title Developers
2072
2073 \previouspage AI translation
2074 \nextpage TS File Format
2075
2076 \image front-coding.png {Illustration showing a code}
2077
2078 Design your application so that it can be adapted to various languages and
2079 regions without engineering changes.
2080
2081 \list
2082 \li \l{TS file format}
2083 \li \l{Text ID based translations}
2084 \li \l{Meta strings reference}
2085 \li \l{CMake Commands in Qt6 LinguistTools}{CMake commands}
2086 \li \l{Examples}
2087 \endlist
2088
2089 For more information, see also:
2090 \list
2091 \li \l {Internationalization with Qt}
2092 \li \l {Writing Source Code for Translation}
2093 \li \l {Localizing Applications}.
2094 \endlist
2095
2096 You can use Qt Creator wizard templates to create Qt widget-based projects
2097 with translation support. For more information, see
2098 \l {Qt Creator: Creating Projects}.
2099
2100 The following video shows how to internationalize and localize a simple
2101 example application:
2102
2103 \youtube xNIz78IPBu0
2104*/
2105
2106/*!
2107 \page linguist-programmers-examples.html
2108 \title Examples
2109
2110 \nextpage Developers
2111
2112 The following examples illustrate how to prepare Qt applications for
2113 translation:
2114
2115 \list
2116 \li \l{arrowpad}{Arrow Pad} is a C++ application that demonstrates how to
2117 make the application load translations depending on the current locale.
2118 It also shows the use of the two-argument form of \c tr() which provides
2119 additional information to the translator.
2120
2121 \li \l{trollprint}{Troll Print} is a C++ application that demonstrates how
2122 to distinguish identical source text in the same context. It also shows
2123 how minimize the translator's work when an application is upgraded.
2124 \endlist
2125*/
2126
2127/*!
2128 \page linguist-ts-file-format.html
2129 \title TS file format
2130
2131 \previouspage Developers
2132
2133 \brief TS file format.
2134
2135 The TS file format used by \QL is described by the
2136 \l{http://www.w3.org/2001/XMLSchema}{XSD} presented below,
2137 which we include for your convenience. Be aware that the format
2138 may change in future Qt releases.
2139
2140 \quotefile ../../../shared/ts.xsd
2141
2142*/
2143
2144/*!
2145 \page linguist-id-based-i18n.html
2146 \title Text ID based translations
2147 \ingroup internationalization
2148
2149
2150 \brief Text ID based internationalization provides support for large scale
2151 projects with many target locales and many texts to translate.
2152
2153 The text ID translation mechanism is an \e {industrial strength} system for
2154 internationalization and localization. Each text in the application has a
2155 unique identifier (text ID) that you use in the source code instead of text.
2156 This makes it much easier to manage large numbers of translated texts.
2157
2158 \section1 Internationalizing with text IDs
2159
2160 When using text IDs instead of plain text, the general method of
2161 internationalizing an application is the same but the details are a bit
2162 different:
2163
2164 \list 1
2165
2166 \li The functions and macros for the text-ID-based translation system are
2167 different from the plain-text system. You use the qsTrId() function instead
2168 of qsTr(), the QT_TRID_NOOP() macro instead of QT_TR_NOOP(),
2169 and QT_TRID_N_NOOP() macro instead of QT_TR_N_NOOP()).
2170
2171 \li Use text IDs as user interface strings rather than plain text
2172 strings. For example, \c {qsTrId("id-back-not-front")}
2173
2174 \li You cannot specify a context parameter with a text ID, and therefore
2175 identically spelled words with different meanings need separate
2176 text IDs. For example, \c {qsTrId("id-back-backstep")} differentiates
2177 the back-step \e {Back} from the \c id-back-not-front \e {Back}.
2178
2179 \li Since context names are not allowed for text-ID-based translations,
2180 \QL lists the IDs in a file without context names.
2181
2182 \li The \e {engineering English} text that you see in the user interface for
2183 development builds is indicated with a \c {//%} comment. If you do not
2184 include this, the text ID is shown in the user interface. This is
2185 especially important when you have texts with parameters. The \c {//%}
2186 comment needs to include the parameters indicators in the string. For
2187 example, \c {//% "Number of files: %1"}
2188
2189 \li The \c {//:} comments that provide extra information to the translator
2190 are optional in the plain-text system. However, with the text-ID-based
2191 system, this extra information becomes essential because without it you only
2192 have the text ID and the translator might not be able to make a sensible
2193 translation from that without further context. You can use long descriptive
2194 text IDs and no comments, but comments are often easier to understand.
2195
2196 \endlist
2197
2198 The side-by-side code snippets below show a comparison of text-ID -based and
2199 plain-text-based translations:
2200
2201 \table
2202 \header
2203 \li text-ID-based
2204 \li plain-text-based
2205 \row
2206 \li
2207 \code
2208 Text {
2209 id: backTxt;
2210 //: The back of the object, not the front
2211 //% "Back"
2212 //~ Context Not related to back-stepping
2213 text: qsTrId("id-back-not-front");
2214 }
2215 \endcode
2216
2217 \li
2218 \code
2219 Text {
2220 id: backTxt;
2221 //: The back of the object, not the front
2222 //~ Context Not related to back-stepping
2223 text: qsTr("Back","Not front")
2224 }
2225 \endcode
2226 \endtable
2227
2228 \section1 Localizing with text IDs
2229
2230 Localizing with text IDs follows much the same process as for plain text.
2231
2232 You use the \l{Using lupdate}{lupdate} tool to generate the TS files where
2233 you add the translations. The source values in the translation files will be
2234 text IDs rather than plain text, and therefore you need either descriptive
2235 text IDs or good additional comments, or both to ensure that the translations
2236 are accurate.
2237
2238 The example text-ID-based user interface text from above results in the following
2239 content in the .ts file:
2240
2241 \code
2242 <message id="id-back-not-front">
2243 <source>Back</source>
2244 <extracomment>The back of the object, not the front</extracomment>
2245 <translation type="unfinished"></translation>
2246 <extra-Context>Not related to back-stepping</extra-Context>
2247 </message>
2248 \endcode
2249
2250 If there is no translation available for a given text (which is
2251 generally the case until late in development), the text ID will be shown in
2252 the user interface rather than a proper text. In order to make the application
2253 more usable for testing, you can make \c lrelease use the \e {Engineering English}
2254 source text (from the \c {//%} comments) as the translated text and mark it with
2255 some indicator, such as an exclamation mark (!), so you can see texts that
2256 are not yet translated.
2257
2258 \section2 Grouping ID-Based Translations
2259
2260 You can assign each ID-based translation a \e label to organize
2261 ID-based entries of large projects into smaller groups.
2262 To assign a \e label to an ID-based entry, add a \c{//@} comment
2263 naming the label, for example in C++:
2264 \code cpp
2265 //% "Open file"
2266 //@ FileOperations
2267 qtTrId("msg.open");
2268 \endcode
2269 Or in QML:
2270 \code qml
2271 //% "Open file"
2272 //@ FileOperations
2273 qsTrId("msg.open");
2274 \endcode
2275 When you open the TS file in \l {Qt Linguist}, the ID-based entries with
2276 the same \e label are grouped together, similar to text-based
2277 entries that are grouped by context.
2278 Any item without a \e label appears under \c{<unnamed label>}.
2279 \note Label names have no effect on lookup or uniqueness: IDs remain globally
2280 unique and can still be loaded via \c{qtTrId("msgid")} without referencing a
2281 label. The label tag is used only to improve the translator's navigation
2282 and does not change runtime behavior.
2283
2284 \section3 Automatic Label Generation
2285
2286 Instead of manually specifying label names, you can use placeholders
2287 to automatically generate labels based on the code structure:
2288
2289 \list
2290 \li \c{//@ <context>} - Automatically uses the full context (namespace::class)
2291 \li \c{//@ <class>} - Automatically uses only the class name (without namespaces)
2292 \li \c{//@ <file>} - Automatically uses the source filename
2293 \endlist
2294
2295 \section4 Combining Placeholders
2296
2297 Placeholders can be combined with custom text to create more descriptive labels:
2298
2299 \list
2300 \li \c{//@ <file>:<class>} - Combines filename and class: \c{filehandler.cpp:FileHandler}
2301 \li \c{//@ <context>_customSuffix} - Adds suffix: \c{MyApp::FileHandler_customSuffix}
2302 \li \c{//@ module_<file>_<class>-label} - Custom prefix and suffix: \c{module_filehandler.cpp_FileHandler-label}
2303 \li \c{//@ <context>:<file>} - Context with file: \c{MyApp::FileHandler:filehandler.cpp}
2304 \endlist
2305
2306 For example, in C++:
2307 \code cpp
2308 namespace MyApp {
2309 class FileHandler : QObject {
2310 Q_OBJECT
2311 void open() {
2312 //% "Open file"
2313 //@ <context>
2314 qtTrId("msg.open"); // Label: MyApp::FileHandler
2315
2316 //% "Save file"
2317 //@ <class>
2318 qtTrId("msg.save"); // Label: FileHandler
2319
2320 //% "Export"
2321 //@ <file>
2322 qtTrId("msg.export"); // Label: filehandler.cpp
2323 }
2324 };
2325 }
2326 \endcode
2327
2328 Or in QML:
2329 \code qml
2330 Item {
2331 id: myComponent
2332 Component.onCompleted: {
2333 //% "Loading"
2334 //@ <context>
2335 qsTrId("msg.loading") // Label: <component-name>
2336
2337 //% "Ready"
2338 //@ <file>
2339 qsTrId("msg.ready") // Label: main.qml
2340
2341 //% "Initialized"
2342 //@ <file>:<context>-state
2343 qsTrId("msg.init") // Label: main.qml:<component-name>-state
2344 }
2345 }
2346 \endcode
2347
2348 Auto labels are particularly useful in large projects where manually
2349 managing label names across many files can be tedious. They ensure
2350 consistent grouping based on code structure and give hints to translators
2351 about where the translation will be used.
2352
2353 \note When using \c{<class>} in C++ code outside any classes, a warning
2354 will be issued and \c{<unnamed>} will be used in the generated label.
2355
2356 \note Using \c{<class>} in QML will generate a
2357 warning and \c{<unnamed>} will be used, since QML
2358 components are not classes. Use \c{<context>} instead to get the
2359 component name, or \c{<file>} to get the QML filename.
2360
2361 \note Auto labels only work with ID-based translations (\c qtTrId, \c qsTrId).
2362 Using auto labels with text-based translations (\c tr, \c qsTr) will generate
2363 a warning and the label will be ignored.
2364
2365 \section1 CMake configuration
2366
2367 When building with CMake, use the prefix \c qml_ for .ts files.
2368 For example, \c qml_en.ts. In the CMakeLists.txt file, add the
2369 \l qt_add_translations function, where you list the *.ts files
2370 as values of \c TS_FILES, and set the value of RESOURCE_PREFIX to the
2371 URI of the main.qml file for the project followed by /i18n:
2372
2373 \badcode
2374 qt_add_translations(${CMAKE_PROJECT_NAME}
2375 TS_FILES i18n/qml_de_DE.ts i18n/qml_en_US.ts
2376 RESOURCE_PREFIX Main/i18n
2377 )
2378 \endcode
2379
2380 \section1 Advanced use with qmake
2381
2382 For projects that target a large number of locales, you can remove the
2383 TRANSLATIONS info from the .pro file and, instead, manage the translations
2384 with a separate script. The script can call \c lrelease and \c lupdate for each of
2385 the desired targets.
2386
2387 The updates could be scripted something like this:
2388
2389 \code
2390 lupdate -recursive <project-dir> -ts <project-dir>/i18n/myapp-text_en_GB.ts
2391 lupdate -recursive <project-dir> -ts <project-dir>/i18n/myapp-text_en_US.ts
2392 ...
2393 \endcode
2394
2395 The generation of the final .qm files could be scripted something like this:
2396
2397 \code
2398 lrelease <project-dir>/i18n/myapp-text_en_GB.ts
2399 lrelease <project-dir>/i18n/myapp-text_en_US.ts
2400 ...
2401 \endcode
2402
2403*/
2404
2405/*!
2406 \page linguist-meta-strings-reference.html
2407 \title Meta strings reference
2408 \ingroup internationalization
2409
2410 \previouspage Text ID based translations
2411
2412 \brief Reference guide for meta strings used in Qt's translation system.
2413
2414 Meta strings are special comments that provide additional information to
2415 lupdate and \QL for translation processing. They use specific
2416 prefixes to identify their purpose and can be used in C++, QML, and Python code.
2417
2418 \section1 Meta string syntax overview
2419
2420 Meta strings are special comments that use specific prefixes to provide lupdate
2421 with additional information about translations:
2422
2423 \table
2424 \header
2425 \li Meta String
2426 \li Purpose
2427 \li Usage
2428 \row
2429 \li \c{//:}
2430 \li Extra comment for translators
2431 \li Provides context and guidance to help translators
2432 \row
2433 \li \c{//%}
2434 \li Source text (engineering English)
2435 \li Defines display text for ID-based translations during development
2436 \row
2437 \li \c{//@}
2438 \li Label for grouping
2439 \li Organizes ID-based translations into logical groups
2440 \row
2441 \li \c{//~}
2442 \li Extra key-value metadata
2443 \li Stores additional custom information about the translation
2444 \row
2445 \li \c{// TRANSLATOR}
2446 \li Magic comment for context
2447 \li Provides context information about the class or file
2448 \endtable
2449
2450 \note The \c{//=} meta string for message ID mapping is deprecated and should not be used in new code.
2451
2452 \section1 Translator comments (//:)
2453
2454 Use \c{//:} comments to provide additional context and guidance to translators.
2455 These comments appear in the \QL translation interface and help
2456 translators understand the meaning and usage of the text.
2457
2458 \section2 C++ example
2459 \code cpp
2460 //: Button to navigate backwards in the application
2461 tr("Back");
2462
2463 //: This is a file menu item that opens an existing document.
2464 //: Keep translation short to fit in menu.
2465 tr("Open");
2466 \endcode
2467
2468 \section2 QML example
2469 \code qml
2470 Button {
2471 //: Emergency stop button - must be clearly visible
2472 text: qsTr("STOP")
2473 }
2474 \endcode
2475
2476 \section2 Python example
2477 \code python
2478 #: Button to navigate backwards in the application
2479 self.tr("Back")
2480
2481 #: This is a file menu item that opens an existing document.
2482 #: Keep translation short to fit in menu.
2483 self.tr("Open")
2484 \endcode
2485
2486 Multiple translator comments can be used for the same string and will be
2487 concatenated with newlines in the TS file.
2488
2489 \section2 TS file format
2490
2491 Translator comments appear as \c{<extracomment>} elements in the TS file:
2492
2493 \code xml
2494 <message>
2495 <source>Back</source>
2496 <extracomment>Button to navigate backwards in the application</extracomment>
2497 <translation type="unfinished"></translation>
2498 </message>
2499 \endcode
2500
2501 \section1 Source text (//%)
2502
2503 The \c{//%} meta string defines the \e{engineering English} text that appears
2504 in the user interface during development when using ID-based translations.
2505 This is essential for making the application usable before translations
2506 are complete.
2507
2508 \section2 C++ example
2509 \code cpp
2510 //% "Save Document"
2511 qtTrId("file.save");
2512
2513 //% "Found %n items"
2514 qtTrId("search.results", count);
2515 \endcode
2516
2517 \section2 QML example
2518 \code qml
2519 Text {
2520 //% "Welcome to the application"
2521 text: qsTrId("welcome.message")
2522 }
2523 \endcode
2524
2525 \section2 Important notes
2526 \list
2527 \li Include parameter placeholders (%1, %n) in the source text
2528 \li The source text should be production-ready English
2529 \li Without //% comments, the text ID itself appears in the UI
2530 \endlist
2531
2532 \section2 TS file format
2533
2534 Source text appears as the \c{<source>} element:
2535
2536 \code xml
2537 <message id="file.save">
2538 <source>Save Document</source>
2539 <translation type="unfinished"></translation>
2540 </message>
2541 \endcode
2542
2543 \section1 Labels (//@)
2544
2545 Use \c{//@} meta strings to organize ID-based translations into logical
2546 groups or categories within \QL. This is particularly useful
2547 for large projects with many translation strings.
2548
2549 \note The \c{//@} meta string is only intended for ID-based translations
2550 (qtTrId/qsTrId) and should not be used with text-based translations (tr/qsTr).
2551
2552 \section2 C++ example
2553 \code cpp
2554 //% "New Document"
2555 //@ FileOperations
2556 qtTrId("file.new");
2557
2558 //% "Print Document"
2559 //@ FileOperations
2560 qtTrId("file.print");
2561
2562 //% "Connection failed"
2563 //@ NetworkErrors
2564 qtTrId("network.error.connection");
2565 \endcode
2566
2567 \section2 QML example
2568 \code qml
2569 Button {
2570 //% "Login"
2571 //@ Authentication
2572 text: qsTrId("auth.login")
2573 }
2574 \endcode
2575
2576 \note Labels are not applicable to Python translations since Python only supports
2577 text-based translations (self.tr()) and not ID-based translations.
2578
2579 Strings with the same label appear grouped together in \QL,
2580 making it easier for translators to work on related content.
2581
2582 For automatic label generation using placeholders like \c{<context>}, \c{<class>},
2583 \c{<file>}, and their combinations, see \l{Automatic Label Generation}.
2584
2585 \section2 TS file format
2586
2587 Labels appear as a \c{label} element:
2588
2589 \code xml
2590 <message id="file.new" label="FileOperations">
2591 <source>New Document</source>
2592 <label>FileOperations</label>
2593 <translation type="unfinished"></translation>
2594 </message>
2595 \endcode
2596
2597 \section1 Extra metadata (//~)
2598
2599 The \c{//~} meta string allows you to attach arbitrary key-value metadata
2600 to translations. This can be used for custom processing or translator
2601 guidance.
2602
2603 \section2 Syntax
2604 \code
2605 //~ key value
2606 //~ key "quoted value with spaces"
2607 \endcode
2608
2609 \section2 C++ example
2610 \code cpp
2611 //% "Error"
2612 //: Critical system error dialog
2613 //~ Severity High
2614 //~ MaxLength "20"
2615 //~ Context "Error dialogs"
2616 qtTrId("system.error");
2617 \endcode
2618
2619 \section2 QML example
2620 \code qml
2621 Text {
2622 //% "Loading..."
2623 //~ Context "Progress indicators"
2624 //~ ShowDuration "true"
2625 text: qsTrId("progress.loading")
2626 }
2627 \endcode
2628
2629 \section2 Python example
2630 \code python
2631 #~ Severity High
2632 #~ Context "Error dialogs"
2633 self.tr("Critical system error")
2634 \endcode
2635
2636 \section2 TS file format
2637
2638 Extra metadata appears as \c{<extra-*>} elements in the TS file and can be
2639 processed by custom tools or translation workflows.
2640
2641 \code xml
2642 <message id="system.error">
2643 <source>Error</source>
2644 <comment>Critical system error dialog</comment>
2645 <translation type="unfinished"></translation>
2646 <extra-Severity>High</extra-Severity>
2647 <extra-MaxLength>20</extra-MaxLength>
2648 <extra-Context>Error dialogs</extra-Context>
2649 </message>
2650 \endcode
2651
2652 \section2 Recognized extra keys
2653
2654 While any key can be used with \c{//~}, the \c no-wrap flag within
2655 \c po-flags is recognized by \c lconvert. See \l{PO format-specific options}.
2656
2657 \section1 TRANSLATOR magic comments
2658
2659 \c{TRANSLATOR} comments provide context information about a class or
2660 source file to help translators understand where translations are used.
2661
2662 \section2 C++ example
2663 \snippet doc_src_linguist-manual.cpp 5
2664
2665 \section2 QML example
2666 \code qml
2667 // TRANSLATOR LoginDialog Login dialog for user authentication
2668 Item {
2669 Text {
2670 text: qsTr("Username")
2671 }
2672 }
2673 \endcode
2674
2675 \section2 Python example
2676 \code python
2677 # TRANSLATOR MainWindow
2678 #
2679 # Main application window containing the primary user interface.
2680 # Keep button labels concise due to space constraints.
2681 #
2682 class MainWindow(QMainWindow):
2683 def setupUi(self):
2684 self.tr("File") # translations for this context
2685 \endcode
2686
2687 \section2 TS file format
2688
2689 TRANSLATOR comment appear as a \c{<message>} elements with empty source text
2690 on the \c{<context>} element:
2691
2692 \code xml
2693 <context>
2694 <name>Main</name>
2695 <message>
2696 <source></source>
2697 <comment>LoginDialog Login dialog for user authentication</comment>
2698 <translation></translation>
2699 </message>
2700 </context>
2701 \endcode
2702
2703 \section1 Combining meta strings
2704
2705 Meta strings can be combined to provide comprehensive translation metadata:
2706
2707 \section2 Complete C++ example
2708 \code cpp
2709 //: File dialog - confirm destructive action
2710 //: This will permanently delete the selected files
2711 //% "Delete Selected Files"
2712 //@ FileOperations
2713 //~ Severity High
2714 //~ RequiresConfirmation "true"
2715 qtTrId("file.delete.confirm");
2716 \endcode
2717
2718 \section2 Complete QML example
2719 \code qml
2720 Text {
2721 //: Shows current connection status to server
2722 //: Updates automatically every few seconds
2723 //% "Connected to server"
2724 //@ NetworkStatus
2725 //~ UpdateFrequency "5000ms"
2726 //~ Color "green"
2727 text: qsTrId("status.connected")
2728 }
2729 \endcode
2730
2731 \section1 Best practices
2732
2733 \list
2734 \li Use translator comments (//:) generously to provide context
2735 \li Always include source text (//%) for ID-based translations
2736 \li Group related translations using labels (//@) in large projects
2737 \li Place meta strings immediately before the translation function call
2738 \li Keep translator comments clear and concise but informative
2739 \li Use consistent naming for labels and extra metadata keys
2740 \endlist
2741*/