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. translation of button texts
Qt 6.11 is out! See what's new in the release blog

translation of button texts

Scheduled Pinned Locked Moved Solved General and Desktop
27 Posts 4 Posters 5.2k Views 2 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #15

    How big is the qm file? Are you sure it contains any translations?

    HoMaH 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      How big is the qm file? Are you sure it contains any translations?

      HoMaH Offline
      HoMaH Offline
      HoMa
      wrote on last edited by
      #16

      @Christian-Ehrlicher I had the same Idea ;) it is a bit more then 200k - and it is the same that you get when building Qt\5.15.1\Src\qttranslations in the distribution.
      Best regards
      Holger

      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #17

        Ok, just wanted to be sure.

        I would suggest you to create a small test example which loads the qm file from disk providing a full path. Then see if it works. A simple main.cpp would be enough.
        Did you build Qt on your own?

        HoMaH 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          Ok, just wanted to be sure.

          I would suggest you to create a small test example which loads the qm file from disk providing a full path. Then see if it works. A simple main.cpp would be enough.
          Did you build Qt on your own?

          HoMaH Offline
          HoMaH Offline
          HoMa
          wrote on last edited by
          #18

          @Christian-Ehrlicher I actually did exactly that. I create an empty widget project, added two buttons to the form. In one I opened a Yes No Message box and found the texts to be OK (ja/nein). However: the file open dialog was a disapointment: this also has englisch texts. No Idea where to go from here...

          best regards
          Holger

          JonBJ 1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #19

            The file open dialog comes from the os (when you use the static versions) - there is nothing Qt can do against it.

            1 Reply Last reply
            2
            • HoMaH HoMa

              @Christian-Ehrlicher I actually did exactly that. I create an empty widget project, added two buttons to the form. In one I opened a Yes No Message box and found the texts to be OK (ja/nein). However: the file open dialog was a disapointment: this also has englisch texts. No Idea where to go from here...

              best regards
              Holger

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #20

              @HoMa
              I was going to say similar to @Christian-Ehrlicher : I don't think you've ever shown which call you are making for " the file open dialog " ? Though even the static ones seem to depend on which OS, which I don't think you've said either?
              https://doc.qt.io/qt-5/qfiledialog.html#getOpenFileName

              On Windows, and macOS, this static function will use the native file dialog and not a QFileDialog.

              Depending on which call you want to use, you could try the corresponding Qt dialog, and see what you think of it, with a QFileDialog instance and QFileDialog::DontUseNativeDialog set?

              EDIT I happened just now to come across https://forum.qt.io/topic/74854/change-qfiledialog-buttons-text/9 :

              BTW: changing the cancel button works (on WIndows) if you do not use the native dialog:

              OpenFile.setOption(QFileDialog::DontUseNativeDialog);
              OpenFile.setLabelText(QFileDialog::Reject, tr("Cancell change"));

              HoMaH 1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #21
                This post is deleted!
                1 Reply Last reply
                0
                • JonBJ JonB

                  @HoMa
                  I was going to say similar to @Christian-Ehrlicher : I don't think you've ever shown which call you are making for " the file open dialog " ? Though even the static ones seem to depend on which OS, which I don't think you've said either?
                  https://doc.qt.io/qt-5/qfiledialog.html#getOpenFileName

                  On Windows, and macOS, this static function will use the native file dialog and not a QFileDialog.

                  Depending on which call you want to use, you could try the corresponding Qt dialog, and see what you think of it, with a QFileDialog instance and QFileDialog::DontUseNativeDialog set?

                  EDIT I happened just now to come across https://forum.qt.io/topic/74854/change-qfiledialog-buttons-text/9 :

                  BTW: changing the cancel button works (on WIndows) if you do not use the native dialog:

                  OpenFile.setOption(QFileDialog::DontUseNativeDialog);
                  OpenFile.setLabelText(QFileDialog::Reject, tr("Cancell change"));

                  HoMaH Offline
                  HoMaH Offline
                  HoMa
                  wrote on last edited by
                  #22

                  @JonB Thx for your answer - but I can not get anything from your links. I only get an error message

                  JonBJ 1 Reply Last reply
                  0
                  • HoMaH HoMa

                    @JonB Thx for your answer - but I can not get anything from your links. I only get an error message

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #23

                    @HoMa
                    This forum has added the : I typed to the end of the Url :(
                    It should be https://forum.qt.io/topic/74854/change-qfiledialog-buttons-text/9, I will correct it now.
                    The other links should be fine.

                    1 Reply Last reply
                    0
                    • HoMaH Offline
                      HoMaH Offline
                      HoMa
                      wrote on last edited by
                      #24

                      Now - which calls I expect to be translated ...

                      I would like this message box to have "ja" and "nein" :

                      QMessageBox::question(this, "Titel", "Eine Nachricht");
                      

                      And it would be even better if this was german, too:

                      QString dir(getUserData(keyOutdir, QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)));
                       dir = QFileDialog::getExistingDirectory(parent, qsl("Ausgabeverzeichnis"), dir,
                                  QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
                      
                      1 Reply Last reply
                      0
                      • Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #25

                        Please start with this basic example

                        
                        int main(int argc, char *argv[])
                        {
                            QApplication a(argc, argv);
                            QTranslator t;
                            if (!t.load("qt_de.qm", "C:/Qt5/5.15.1/mingw81_64/translations/"))
                                return -1;
                            a.installTranslator(&t);
                            QMessageBox::question(nullptr, t.translate("QMessageBox", "Show Details..."), t.translate("QMessageBox", "Hide Details..."));
                            return a.exec();
                        }
                        
                        HoMaH 1 Reply Last reply
                        2
                        • Christian EhrlicherC Christian Ehrlicher

                          Please start with this basic example

                          
                          int main(int argc, char *argv[])
                          {
                              QApplication a(argc, argv);
                              QTranslator t;
                              if (!t.load("qt_de.qm", "C:/Qt5/5.15.1/mingw81_64/translations/"))
                                  return -1;
                              a.installTranslator(&t);
                              QMessageBox::question(nullptr, t.translate("QMessageBox", "Show Details..."), t.translate("QMessageBox", "Hide Details..."));
                              return a.exec();
                          }
                          
                          HoMaH Offline
                          HoMaH Offline
                          HoMa
                          wrote on last edited by HoMa
                          #26

                          @Christian-Ehrlicher said in translation of button texts:

                          QMessageBox::question(nullptr, t.translate("QMessageBox", "Show Details..."), t.translate("QMessageBox", "Hide Details..."));

                          Hi Christian! Wow - this made a difference. And I have to admit that I don't know why. With the call from you

                          QMessageBox::question(nullptr, t.translate("QMessageBox", "Show Details..."), t.translate("QMessageBox", "Hide Details..."));
                          

                          I get not only a german title and message, but also the buttons are in german - that's great!
                          However - when I call

                          QMessageBox::question(this, "Titel", "Eine Nachricht");
                          

                          in a different function the buttons are yes and no! Does QMessageBox need QTranslator be in scope or ...

                          So you solved it - kind of - and my msg box is still not in german ... should I laugh or cry ;) ?

                          Anyhow: that was a great step forward - thank you. I would appreciate if you have additional thoughts...

                          regards
                          Holger

                          PS: I played around and with QTranslator being a global object all messageboxes say "ja" and "nein" ...

                          1 Reply Last reply
                          0
                          • HoMaH Offline
                            HoMaH Offline
                            HoMa
                            wrote on last edited by HoMa
                            #27

                            Hi all - and thanks a lot to all who wanted to help.

                            I write this as a final note, because I consider this as solved. My solution looks now like this:

                            QTranslator* pTrans = new QTranslator();
                                if( pTrans->load(translationFile, path))
                                    if( QCoreApplication::installTranslator(pTrans)) {
                                        qInfo() << "Successfully installed language file " << translationFile;
                                        return;
                                    }
                                qCritical() << "failed to load translations " << translationFile;
                            

                            So the QTranslator, which is "installed" into the application does never run out of scope. One might consider this a leak - but as I do not intend to offer a switch of language I guess for me this is OK.
                            So the take away for everyone who has similar problems: let your QTranslate survive, then it will work for you!

                            Best regards
                            Holger

                            PS: This will translate MessageBox buttons as well as Wizard buttons. It does not work for File dialogs which are provided from the OS.

                            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