Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Qt translation not working

[SOLVED] Qt translation not working

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 6.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tomko222
    wrote on last edited by
    #1

    I tried to add multilanguage support in my new program so I just added same code as in my other program where translations were working. But in this case everything remains untranslated... TRANSLATIONS += translation-pl_PL.ts added to .pro file, .ts translated, .qm generated and added to resources (/translations/translation-pl_PL.qm) so I don't think I forgot about doing something necessary...

    main.cpp where translation is loaded:
    @
    #include "mainwindow.h"
    #include <QtGui>
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));

    //checking available program translations
    QFile tempFile&#40;":/translations/translation-"+QLocale::system(&#41;.name(&#41;+".qm");
    if(tempFile.exists())
    {
        //program is translated to system default language
        qDebug("translation to system default language available");
        //Qt translations
        qDebug("loading qt translations");
        QTranslator qtTranslator;
        bool check;
        check=qtTranslator.load("qt_"+QLocale::system&#40;&#41;.name(&#41;, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
        if(check)
        {
            qDebug("qtTranslator load true");
        }else{
            qDebug("qtTranslator load false");
        }
        a.installTranslator(&qtTranslator);
    
        //program translations
        qDebug("loading program translations");
        QTranslator programTranslator;
        check=programTranslator.load(":/translations/translation-"+QLocale::system&#40;&#41;.name(&#41;);
        if(check)
        {
            qDebug("programTranslator load true");
        }else{
            qDebug("programTranslator load false");
        }
        a.installTranslator(&programTranslator);
    
    }
    MainWindow w;
    w.show();
    
    return a.exec(&#41;;
    

    }
    @

    Debug info:
    @
    translation to system default language available
    loading qt translations
    qtTranslator load true
    loading program translations
    programTranslator load true
    @
    So everything is loading but translation is not working...

    What can be wrong here?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Are you sure that you are not getting the english translator ?

      Did you add tr() around your texts ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tomko222
        wrote on last edited by
        #3

        pl_PL translator is loaded. I have tr().

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          The are you sure that the translation file contains the correct texts ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tomko222
            wrote on last edited by
            #5

            .ts is translated - I can see translations inside it. .qm is generated from it so I think that it should be ok too.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              If you have the translation files from your other programs handy, can you try to use one of them to see if it behaves better ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • T Offline
                T Offline
                tomko222
                wrote on last edited by
                #7

                I found what was the problem... I defined qtTranslator and programTranslator in if...

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Great you found out !

                  Don't forget to update the thread's title so that other forum users may know that a solution has been found :)

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved