Qt TS
Qt TS localization for Qt applications.
Translate the .ts files that lupdate writes, reuse earlier translations, check placeholders, and write translated .ts files for lrelease. Your Qt project keeps extraction, the build, and runtime loading.
- Input
.tsfiles written by lupdate- Output
- Translated
.tsfiles, such asapp_de.ts - Runtime
.qmfiles built by lrelease, loaded byQTranslator- Preview
- None: strings are translated in the table
On this page
Tutorial
Localize Qt .ts files with Lingobit, step by step.
Four steps from the .ts files lupdate writes to translated files for lrelease.
lupdate extracts, Lingobit translates, lrelease builds.
Your code marks text with tr() or qsTr(), and lupdate collects it into .ts files. Lingobit translates those files and writes one translated .ts file for each language. lrelease compiles them into .qm files, which your application loads at runtime.
Lingobit does
- Translates the strings of your
.tsfiles, with their context and translator comments. - Reuses earlier translations and the translation memory.
- Checks placeholders such as
%1, empty and too long translations, and more. - Writes a translated
.tsfile for each language.
Your Qt project keeps
- Marking strings with
tr()andqsTr(), and running lupdate. - Compiling
.tsinto.qmwith lrelease or your CMake or qmake target. - Loading the translation at runtime and the language switch.
- Qt Designer, QML, and the final test in the running application.
Reference
At startup, QTranslator picks the .qm file by its name.
Lingobit writes app_de.ts, lrelease turns it into app_de.qm, and your code asks QTranslator to load a file for the user's language. For German (Germany) it tries app_de_DE.qm, then app_de.qm.
- One file serves a language.
app_de.qmserves German in Germany, Austria, and Switzerland; addapp_de_CH.qmonly when Swiss German text differs. - A missing translation shows the source text. A string that is new or still untranslated appears in the source language; it does not break the application.
QTranslator translator;
if (translator.load(QLocale(), "app", "_", ":/i18n"))
app.installTranslator(&translator);
Choose the language in your app.
Load the translation before the first window is created. To let users pick the language, keep their choice and use it instead of the system language:
- List the languages you ship from the
.qmfiles in your resources or folder. - Read the saved choice or a command-line switch; otherwise use
QLocale::system(). - Load and install the translator before
MainWindowis created. - Switch while running by installing another translator and calling
retranslateUionLanguageChange, or restart.
QSettings settings;
const QString lang = settings.value("language", QLocale::system().name()).toString();
QTranslator translator;
if (translator.load("app_" + lang, ":/i18n"))
app.installTranslator(&translator);
MainWindow window;
window.show();
Context and comments travel with each string.
Context
lupdate puts each string in a context, usually the class name. Lingobit keeps it with the string and matches translations by context and source text when lupdate refreshes the file. Rename a class, and its strings arrive as new.
Translator comments
A comment written with //: above a tr() call reaches translators with the string. Use it for short or ambiguous text, such as a button label or a unit.
//: Button that sends the order; keep it short
auto send = new QPushButton(tr("Send"), this);
Do and don't.
Do
- Run lupdate before every handoff, and add the refreshed
.tsfiles. - Use
%1,%2withQString::arg, so translators can change the order. - Add
//:comments to short and ambiguous strings. - Keep
.tsnames and language codes in line with your loading code. - Ship Qt's own translations, such as
qtbase_de.qm, for the standard dialogs.
Don't
- Build sentences in code from translated pieces.
- Edit the translated
.tsfiles by hand: the next Create overwrites them. - Rename classes after translation has started without a reason.
- Send C++, QML, or
.uifiles to translators. - Install the translator after the windows are created.
Troubleshooting.
| Symptom | Likely cause | What to do |
|---|---|---|
| The application stays in English | No .qm file was built or shipped for the language, its name does not match the loading code, or the translator was installed after the windows were created | Run lrelease on the translated .ts files, check the file name and folder, and install the translator first |
| Some strings stay in English | They are not marked with tr() or qsTr(), or lupdate has not run since they were added | Mark them, run lupdate, and run Scan for Changes in Lingobit |
| Translations are New again after lupdate | The source text changed, or the context changed because a class was renamed | Keep contexts stable; earlier translations stay in the translation memory and come back as suggestions |
| Standard Qt dialogs stay in English | Qt's own translations are not loaded | Load qtbase_de.qm from the Qt translations folder as well |
| German text is cut off in the application | .ts files have no preview, so long text shows only in the running application | Set a maximum length for the strings in Lingobit; Validation reports translations that exceed it. Check the screens in the running application |
| The application crashes with one language | A translation breaks a placeholder that arg() expects | Run Validation: it reports translations whose placeholders do not match the source |
The Qt sample.
Localizer installs a Qt sample with its project, so you can try the steps above without your own application.
Qt_Localization.ts, written by lupdate from a qmake project, and the Lingobit projectQt Localization.loc.- Create Localized Files writes the translated
.tsfiles. compile_ts.cmdruns lrelease on them and makes the.qmfiles.qt_localization.exe esstarts the Spanish version; without an argument the sample uses the Windows language.
More about Qt localization.
Qt .ui files and QML
Qt Designer .ui files and QML files can contain user-facing strings, but the handoff to Lingobit is still the generated .ts files: lupdate extracts the strings from .ui, QML, C++, and the other configured files, translators work with the .ts files, and developers compile them into .qm and check the UI in the application.
Qt Designer layout changes, QML component behavior, the Qt resource system, and CMake or qmake target configuration stay in the Qt project.
Clear boundaries
- Lingobit translates Qt
.tsfiles; it does not localize compiled Qt applications directly. - It does not replace lupdate, lrelease, or Qt Designer, and it does not compile
.tsfiles into.qmfiles. - Runtime language loading, fallback, and packaging the
.qmfiles stay with the application.
Related paths
- Localization QA — Validation, placeholder checks, and Crash Finder.
- Release workflow — Scan for Changes and translated files for every release.
- Python (PO) — The same translation stage for gettext catalogs.
- Migration — Bring translations from Qt Linguist and earlier tools.