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] QTranslator not working?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QTranslator not working?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 5.8k 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.
  • M Offline
    M Offline
    maximus
    wrote on last edited by
    #1

    Hi guys,

    I'm trying out the translator system in QT for the first time.
    I fallowed the guide :
    http://qt-project.org/doc/qt-5.0/qtdoc/internationalization.html

    -First genereted the .ts file
    -Edited the .ts file with Qt Linguist (completed the translation 100%)
    -Compiled the .ts file into .qm file in QtCreator

    The .qm file and .ts file are in the root on my project, here's a screenshot:
    https://www.dropbox.com/s/gv2wraan7au8o75/folderProject.png

    I specify in my main to load a specific .ts file just for testing, but it still show the english text. (see code below)
    Anything I forgot to do?
    Thanks in advance /Merci à l'avance :)

    @int main(int argc, char *argv[]) {

    QApplication a(argc, argv);
    
    QString locale = QLocale::system().name();
    qDebug() << "LOCALE : " << locale;
    
    QTranslator translator;
    translator.load("powervelo_fr");
    a.installTranslator(&translator);
    
    MainWindow w;
    w.show();
    
    return a.exec(&#41;;
    

    }@


    Free Indoor Cycling Software - https://maximumtrainer.com

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

      Hi,

      Without the rest of your code, it's difficult to say what could be wrong. The first guess is: did you surround all your visible texts with tr() ?

      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
      • M Offline
        M Offline
        maximus
        wrote on last edited by
        #3

        I set the text directly in QtCreator interface

        An example of generated code looks like this :
        @groupBox->setTitle(QApplication::translate("MainWindow", "Filter", 0));@

        I think it's good syntax cause the generated .ts file make an entry for it

        Thanks


        Free Indoor Cycling Software - https://maximumtrainer.com

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maximus
          wrote on last edited by
          #4

          Hmm probably a problem with the path of the file

          the boolean return false when I load the file

          @ QTranslator translator;

          bool test = translator.load("powervelo_fr");
          qDebug() << "LOADED? " << test;
          //return false
          a.installTranslator(&translator);@
          

          Free Indoor Cycling Software - https://maximumtrainer.com

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

            Are you sure your file is in the same folder as your executable ?

            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
            • JeroentjehomeJ Offline
              JeroentjehomeJ Offline
              Jeroentjehome
              wrote on last edited by
              #6

              Include in your pro file:
              @
              TRANSLATIONS = HD120_en.ts
              HD120_nl.ts
              HD120_cn.ts
              HD120_pt.ts
              @
              Of at least the ts files you need. That's needed for QtLinguist. Also check if your using a shadow build that your files are in the same as the executable file! Not in your project, but in your debug/release folders!!

              Greetz, Jeroen

              1 Reply Last reply
              0
              • M Offline
                M Offline
                maximus
                wrote on last edited by
                #7

                That was the problem, the files were in the project instead of the release/debug folder

                Thanks guys!


                Free Indoor Cycling Software - https://maximumtrainer.com

                1 Reply Last reply
                0
                • JeroentjehomeJ Offline
                  JeroentjehomeJ Offline
                  Jeroentjehome
                  wrote on last edited by
                  #8

                  If that fixed it, place [SOLVED] in front of your first post!!

                  Greetz, Jeroen

                  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