Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to write a QtQuick app based on Python (PySide) and QML.

I know Qt apps have got their own translation technology, but I would like to stick to gettext for this one. I'd like to know if it's possible to:

  • Mark strings for translation in QML files in a way gettext tools can extract them into a .pot file
  • Have gettext translate QML files at runtime.

I know this is done in the Unity 2D code, in C++, so I'm wondering how it can be done with Python.

Note: I'm talking about using exclusively gettext at runtime, not about converting between gettext and Qt Linguist formats.

share|improve this question

Generally speaking there is no way to use gettext translation in QT because the library uses an internal translation mechanism (Qtranslate and .ts files) as stated here QTBUG-2404.

However, there is a viable alternative.

Shipping with QT there is a toolkit called lconvert that can be used to convert .ts files to .po and vice versa.

So you can extract all of your translation with:


Then use lconvert to obtain a po file:

lconvert -of po -o file.po file.ts

After translation you can convert back the po file to ts:

lconvert -of ts -o file.ts file.po

Then you can use it in your software.

lupdate can bu used both for QT an QtQuick.

share|improve this answer
Thanks for the answer!. I'm aware of the conversion tools, but they won't make gettext load the translations at runtime. I know it is technically possible by overriding the Qt translate call, as the Unity 2D guys do it in C++, I'm just trying to figure out how to do it in Python. – David Planella May 28 '12 at 9:53

You can hack the lupdate's source use something you like to substitute qsTr. (is easyly) and then use you hacked lupdate + lconvert + you custome libintl to achieve use gettext objective.

share|improve this answer
Explain how please. – Kaz Wolfe Nov 25 '13 at 3:00
open the qdeclarative.cpp(in lupdte source code) find "qsTr" substitue it with anything you want, assume use "dsTr". Then use dsTr("you string") in qml. use lconvert generate an pot file after use the modifed lupdate to generate an ts file. The last you need implement and export the dsTr to global context – snyh Nov 25 '13 at 13:08
Go head and put that in the answer. Just as a general rule, always tell how and then give source. – Kaz Wolfe Nov 25 '13 at 18:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.