Important: Please read the Qt Code of Conduct -

[solved] How to translate english to german language during runtime?

  • hello,
    I would like to translate all my strings from english to german. I have create a translation file using cmd line as said here link here. lupdate myproject\ qml\ -ts translation\en_En.ts . Now a file en_EN.ts has been generated in a folder translation. I have opened this file in Qt linguist and i can see all the strings around 138. I have changed the translation file settings from source lang posix to english. These are my final settings:
    source language: English country: any country
    target language: German country: German
    Then release as it has generated me a file en_EN.qm
    Now, How should I make use of this file in my QML code to translate from english to german ?Also switch back to english.
    I am looking for the qml code.
    All my strings are defined like this qsTr("send")
    Thanks a lot :)

  • Lifetime Qt Champion


    I don't know if you still need to do this but a starting points could be this article

  • @SGaist
    Thanks for the quick reply.
    lrelease t1_de.ts after this line it has generated t1_de.qm file. I have just included in pro file TRANSLATIONS = t1_de.ts . Should i include "t1._de.ts" in Resources ? where should i include t1_de.qm file ? because it is just mentioned that it is used by the application at runtime. I am wondering how does it happen if i don't include it.

  • @SGaist
    I can see that from qml this function is invoked but not translating. How do i know that it is loading t1_de.ts file ?i mean any debugging technique ?

        if(language == QString("de")) {
          translator->load("t1_de", ".");
         if(language == QString("en")) {
         emit languageChanged();

  • @vishnu
    works perfect. forgot to run qmake :)

Log in to reply