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. Translate QDialogButtonBox
Forum Updated to NodeBB v4.3 + New Features

Translate QDialogButtonBox

Scheduled Pinned Locked Moved General and Desktop
25 Posts 4 Posters 10.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.
  • C Offline
    C Offline
    cincirin
    wrote on last edited by
    #7

    [quote author="Exotic_Devel" date="1414679912"]Can be in any source file or should be in the file where the text is to be translated?

    I ask this because my application is all baseade in QUiLoader, ie, there is no source file for widgets.[/quote]

    Must be in whatever file that you'll pass to lupdate to be translated.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Salvatello
      wrote on last edited by
      #8

      tr before you put the text?

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cincirin
        wrote on last edited by
        #9

        [quote author="Salvatello" date="1414681047"]tr before you put the text?[/quote]

        no, "tr" should not be.
        QT_TRANSLATE_NOOP marks the string for translation

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Salvatello
          wrote on last edited by
          #10

          If you do not enter the tr .ts file of the language you generate the text to be translated.
          You do lupdate and after irelease ?

          1 Reply Last reply
          0
          • E Offline
            E Offline
            Exotic_Devel
            wrote on last edited by
            #11

            I'm getting warnings

            ../../../TecTracker/Core/gui/connecdialog.cpp: In constructor 'Connecdialog::Connecdialog(QWidget*)':
            ../../../TecTracker/Core/gui/connecdialog.cpp:34:48: warning: statement has no effect [-Wunused-value]
            QT_TRANSLATE_NOOP("QPlatformTheme", "Cancel");
            ^
            ../../../TecTracker/Core/gui/connecdialog.cpp:35:47: warning: statement has no effect [-Wunused-value]
            QT_TRANSLATE_NOOP("QPlatformTheme", "Apply");
            ^
            ../../../TecTracker/Core/gui/connecdialog.cpp:36:46: warning: statement has no effect [-Wunused-value]
            QT_TRANSLATE_NOOP("QPlatformTheme", "&Yes");
            ^
            ../../../TecTracker/Core/gui/connecdialog.cpp:37:45: warning: statement has no effect [-Wunused-value]
            QT_TRANSLATE_NOOP("QPlatformTheme", "&No");
            ^
            ../../../TecTracker/Core/gui/connecdialog.cpp:38:44: warning: statement has no effect [-Wunused-value]
            QT_TRANSLATE_NOOP("QPlatformTheme", "Ok");
            ^

            1 Reply Last reply
            0
            • C Offline
              C Offline
              cincirin
              wrote on last edited by
              #12

              Yes, that's correct because you didn't use the returned char*, it's a compiler warning, but not an error.
              Put an Q_UNUSED macro in front of every QT_TRANSLATE_NOOP and the warning is off:
              Q_UNUSED(QT_TRANSLATE_NOOP(...))

              1 Reply Last reply
              0
              • E Offline
                E Offline
                Exotic_Devel
                wrote on last edited by
                #13

                Sorry for raising the topic, i was kinda busy.

                In my test did not work

                @int main(int argc, char *argv[])
                {
                QApplication app(argc, argv);
                QTranslator translation;
                translation.load("translations/core_connecdialog_ptBr.ts");

                Testdataaccess testdataaccess(&app);
                Testconnecdialog testconnecdialog(&app);
                Testdynamicqtwidgets testedynamicqtwidgets(&app);

                //QTest::qExec(&testedynamicqtwidgets, argc, argv);
                //QTest::qExec(&testdataaccess, argc, argv);
                QTest::qExec(&testconnecdialog, argc, argv);

                app.installTranslator(&translation);
                app.exec();
                }@

                .ts files can be used directly @translation.load("translations/core_connecdialog_ptBr.ts")@ or is necessary to run lrelease?

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

                  ts files are "internationalization sources". You have to run lrelease to get the file for QTranslator to use.

                  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
                  • E Offline
                    E Offline
                    Exotic_Devel
                    wrote on last edited by
                    #15

                    Ok, I run lrelease, qm file was generated, however, nothing was translated. Everything is still in English.

                    My main.cpp

                    @int main(int argc, char *argv[])
                    {
                    QApplication app(argc, argv);
                    QTranslator translation;
                    translation.load("translations/core_connecdialog_ptBr");

                    Testdataaccess testdataaccess(&app);
                    Testconnecdialog testconnecdialog(&app);
                    Testdynamicqtwidgets testedynamicqtwidgets(&app);

                    //QTest::qExec(&testedynamicqtwidgets, argc, argv);
                    //QTest::qExec(&testdataaccess, argc, argv);
                    QTest::qExec(&testconnecdialog, argc, argv);

                    app.installTranslator(&translation);
                    app.exec();
                    }
                    @

                    !http://i60.tinypic.com/wh1c48.png(MyLinguist)!

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      cincirin
                      wrote on last edited by
                      #16

                      Basically you have two errors:
                      a) check the return value of translation.load(...) to be sure the translation is correctly loaded
                      b) I'm not 100% sure about this, but you call installTranslator after your Ui is created. I think in this way you'll have to retranslate the Ui (check dynamic translation in the docs). Anyway, try to move installTranslator before the widgets are created

                      1 Reply Last reply
                      0
                      • E Offline
                        E Offline
                        Exotic_Devel
                        wrote on last edited by
                        #17

                        Ok, worked

                        @int main(int argc, char *argv[])
                        {
                        QApplication app(argc, argv);
                        QTranslator translation;

                        translation.load("translations/core_connecdialog_ptBr");

                        app.installTranslator(&translation);

                        Testdataaccess testdataaccess(&app);
                        Testconnecdialog testconnecdialog(&app);
                        Testdynamicqtwidgets testedynamicqtwidgets(&app);

                        //QTest::qExec(&testedynamicqtwidgets, argc, argv);
                        //QTest::qExec(&testdataaccess, argc, argv);
                        QTest::qExec(&testconnecdialog, argc, argv);

                        app.exec();
                        }
                        @

                        but QDialogButtonBox is not translated.
                        I added QT_TRANSLATE_NOOP, did the translation with Qt Linguist. But still in english.

                        !http://i60.tinypic.com/2nsary8.png(QDialogButtonBox)!

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

                          Do you have

                          @translation.load("translations/core_connecdialog_ptBr");@

                          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
                          • C Offline
                            C Offline
                            cincirin
                            wrote on last edited by
                            #19

                            @Exotic_Devel: your linguist seems to be un-translated. If I look at ConecConfDialog source there are 0(zero) items translated from 7. The same for QPlatformTheme, there are 0(zero) items from 5 translated.

                            So, I don't know how your binary application is ever translated. Maybe it is looking for other "lrelease"-ed translation ? (not the one from screenshot)

                            edit: make sure you save the linguist translation before the "lrelease"

                            1 Reply Last reply
                            0
                            • E Offline
                              E Offline
                              Exotic_Devel
                              wrote on last edited by
                              #20

                              Ok, in Qt Linguist lacked [Translation] => [Done and Next] menu, but is still without translation. Below the images.

                              !http://i61.tinypic.com/34tea2e.png(mylinguist)!
                              !http://i58.tinypic.com/6teqlj.png(mydir)!
                              !http://i59.tinypic.com/21lr3ps.png(mydir2)!

                              1 Reply Last reply
                              0
                              • E Offline
                                E Offline
                                Exotic_Devel
                                wrote on last edited by
                                #21

                                Ok, in Qt Linguist lacked [Translation] => [Done and Next] menu, but is still without translation. Below the images.

                                !http://i61.tinypic.com/34tea2e.png(mylinguist)!
                                !http://i58.tinypic.com/6teqlj.png(mydir)!
                                !http://i59.tinypic.com/21lr3ps.png(mydir2)!

                                1 Reply Last reply
                                0
                                • E Offline
                                  E Offline
                                  Exotic_Devel
                                  wrote on last edited by
                                  #22

                                  Saved and used again lrelease

                                  1 Reply Last reply
                                  0
                                  • E Offline
                                    E Offline
                                    Exotic_Devel
                                    wrote on last edited by
                                    #23

                                    Saved and used again lrelease

                                    1 Reply Last reply
                                    0
                                    • E Offline
                                      E Offline
                                      Exotic_Devel
                                      wrote on last edited by
                                      #24

                                      Unfortunately the solution with QT_TRANSLATE_NOOP did not solve. I opted for the solution mentioned by SGaist.

                                      @qdbb_okcancel->button(QDialogButtonBox::Cancel)->setText(tr("&Cancel"));
                                      @

                                      Now the translation works well

                                      Thank you all

                                      1 Reply Last reply
                                      0
                                      • E Offline
                                        E Offline
                                        Exotic_Devel
                                        wrote on last edited by
                                        #25

                                        Unfortunately the solution with QT_TRANSLATE_NOOP did not solve. I opted for the solution mentioned by SGaist.

                                        @qdbb_okcancel->button(QDialogButtonBox::Cancel)->setText(tr("&Cancel"));
                                        @

                                        Now the translation works well

                                        Thank you all

                                        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