Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved [SOLVED] translator does not install?

    General and Desktop
    2
    6
    1379
    Loading More Posts
    • 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.
    • N
      NinaWeber last edited by NinaWeber

      Hello,
      I am having a very weird problem: I tried the arrowpad example of QT to test QtLinguist. It works fine. I wrote my own little example (even less code than arrowpard) and it didn't work. Here is my code:

      QT       += core gui
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
      TARGET = testLinguist
      TEMPLATE = app
      SOURCES += main.cpp\
              mainwindow.cpp
      TRANSLATIONS = testlinguist_en.ts \
                     testlinguist_de.ts \
                     testlinguist_fr.ts
      HEADERS  += mainwindow.h
      RESOURCES += \
          resources.qrc
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          MainWindow w;
          w.show();
          QString locale = "fr"
          QTranslator translator;
      
          //bool success = translator.load(QString("testlinguist_") + locale); //did not work just placing the file in the same folder as pro file.
          bool success = translator.load(QString(":\\testlinguist_") + locale);
          a.installTranslator(&translator);
          return a.exec();
      }
      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
      {
          QWidget* mainWidget = new QWidget(this);
          setCentralWidget(mainWidget);
          QPushButton* button = new QPushButton(tr("&Press"));
          QGridLayout *mainLayout = new QGridLayout(mainWidget);
          mainLayout->addWidget(button, 0, 1);
          mainWidget->setLayout(mainLayout);
      }
      

      at first the success variable in main.cpp was false (I fixed that by putting the qm file in the resources). Now it loads the qm file (success is true), but there still are no translations made. I did everything exactly like in the arrowpad example.
      Does anybody have any idea what could be going wrong here?
      Thanks for your help!

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        On a side note, please use forward slashes in path, that will make your code cleaner and less error prone.

        Do you only have one text to translate ?

        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 Reply Quote 0
        • N
          NinaWeber last edited by

          this is my test app, I just wrote to test the Linguist. In my real program (where it does not work either) I have of course a lot of text to translate.

          1 Reply Last reply Reply Quote 0
          • N
            NinaWeber last edited by

            I just did some deeper debugging. It seems like the translation file is loaded, but when executing the function tr() this line returns false

             !self->d_func()->translators.isEmpty()
            

            line 1967 in file qcoreapplication.cpp, function

            QString QCoreApplication::translate(const char *context, const char *sourceText,
                                                const char *disambiguation, Encoding encoding, int n)
            

            does someone know what I might be doing wrong?
            I opened the .ts file the lupdate testLinguist.pro produces, I inserted the translations, clicked on the mark as finished icon (the checksign for this text turned yellow), and I ran lrelease testLinguist.pro to get the .qm files (which are loaded successfully according to the return variable success). I just don't know what is going wrong

            1 Reply Last reply Reply Quote 0
            • N
              NinaWeber last edited by

              Ok found the mistake. Really stupidly, I called w.show() in main.cpp too early...

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                So showing it before loading the translator ?

                One thing you can to is implement dynamic translation especially since you are providing several translations.

                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 Reply Quote 0
                • First post
                  Last post