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] translator does not install?

[SOLVED] translator does not install?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 2.0k Views
  • 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 Offline
    N Offline
    NinaWeber
    wrote on last edited by NinaWeber
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • N Offline
        N Offline
        NinaWeber
        wrote on last edited by
        #3

        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
        0
        • N Offline
          N Offline
          NinaWeber
          wrote on last edited by
          #4

          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
          0
          • N Offline
            N Offline
            NinaWeber
            wrote on last edited by
            #5

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

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

              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
              0

              • Login

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