May 2, 2009

how to handle translations for an application that is both qt-only and KDE ?

by orzel
Categories: KDE
Tags: , ,
Comments: 11 Comments

I have the problem for my application Opale, which used to be KDE only and is now both Qt and KDE.

The first thing I’ve done is to switch from *.po (gettext) to *.ts (qt), because Qt can not (or can it ?  tell me how !) handle gettext files. Then, I needed to use qApp->addTranslator() to load the Qt translation files (the *.qm generated from *.ts). So far it’s easy.

But then I had a problem : if I start the application, the strings from KDE are not translated. Especially the menu entries created using KStandardAction::*. The reason is that the application does not load any *.mo, and this is what triggers the loading of KDE messages.

The solution is to give “kdeinit4” as second argument to KAboutData::KAboutData() instead of 0 as is usually done. Instead of trying to load your application translation, fail, and finally not load anything at all, it will load the ones for KDE directly. And you can still use qApp->addTranslator() , isn’t it great ? 🙂

Thanks a lot to tsdgeos and Chusslove on #kde-devel for their help, they are the ones who found out.

If you want an example of how to do, you can refer to Opale’ source, and most importantly to the following files:


  1. Willi says:

    Why did you go for a Qt-only? What is wrong with kdelibs? How could it be fixed?

  2. I need Qt-only in order to provide an easy-to-install application on linux, MacOS and Windows. The Qt-only version is mostly self-contained using Qt’s ressource file. Please don’t tell me I should ask people to install KDE on Windows or Mac just to use Opale…

  3. Christoph says:

    Thanks for the hint. I furthermore plan to look into your code to see howto effectively have both a Qt-only and KDE version.

  4. Giuseppe says:

    “The GNU Gettext PO format, which is commonly used in Open Source projects, is now supported by Qt Linguist.”


  5. Morty says:

    I’d say go for the simplest solution, use both. No need to get to fancy, it only need to work:-)

    Provide both *.po and *.ts files. It should not be to hard to set up a script to automatic convert po->ts or ts->po at build time to keep the two in sync.

  6. anon says:

    Self-contained applications should eventually become a thing of the past…

    I think the KDEWin-Installer should be used for centralized installing and keeping up-to-date all dependencies for every possible KDE/Qt app on Windows. I’ve added a respective lists of visions to the KDEWin-Installer page on Techbase:

  7. giuseppe : i did that before 4.5 was out. Furthermore, even if Linguist support gettext (which is great, but I already had kde tools for that), what i need is different : i need the qt lib to support po files. Does it ?

    Morty : This more complicated that what you think. It is not easy to convert between formats (Qt provides a tool, but far from perfect).

    Anon : sure, ‘thing of the past’. Using technology of today I could not find any better way.

  8. Jaroslav Smid says:

    anon: KDE4 for windows does not have 64bit version, Qt4 does. And it is no fun to install 1GB of useless shit just because of 1 app.

  9. Morty says:

    I didn’t think the formats was that complex. Besides for your own application where you already know the structure of the input, you should not need a general purpose converter knowing every thing of the formats. But it would require some work.

    If the Qt provided tool are not up to the job, what about this one:

  10. anon says:

    Thomas: That was the ‘should be’ part. 🙂 In any case it’s a sad state of affair that even for Qt there is no standard distribution scheme already. I’m sure Qt would be at least a little more popular with the mainstream if it were as easy to find already installed like Flash and Java claim to be.

    Jaroslav: Great trolling there. The base dependencies of KDE are far from 1GB. And that there is no 64bit version yet is not due technical problems but the lack of volunteers maintaining such (KDE for Windows isn’t even officially out of Beta yet). But you sound like you want to help out. 😉

  11. Jaroslav Smid says:

    anon: No, I just like trolling, because I got personality disorder 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *