Translate QDialogButtonBox



  • I'm doing a translation of an application, specifically a GUI interface created with Qt Designer.
    At this interface there is a QDialogButtonBox button, and when i open the TS file with Qt Linguist not appear the QDialogButtonBox button to perform the translation.
    I found some response during a search, however, were not clear to me.


  • Lifetime Qt Champion

    Hi,

    IIRC, you have two options:

    use Qt's translation files

    set yourself the text on QDialogButtonBox's buttons.

    The second one is a bit simpler

    Hope it helps



  • ... or in addition to SGaist manually add all words from Qt source-code in Qt linguist, for example, put anywhere in your code something like this:

    @
    QT_TRANSLATE_NOOP("QPlatformTheme", "Cancel");
    QT_TRANSLATE_NOOP("QPlatformTheme", "Apply");
    QT_TRANSLATE_NOOP("QPlatformTheme", "&Yes");
    QT_TRANSLATE_NOOP("QPlatformTheme", "&No");
    QT_TRANSLATE_NOOP("QPlatformTheme", "OK");
    @

    This is for Qt5. For Qt4 you'll have to change QPlatformTheme with QDialogButtonBox.

    After that all words will be available in Qt linguist and you can translate them just like any other word(s)



  • Two questions, where should I put these lines? What is context that should be passed to the QT_TRANSLATE_NOOP macro?



  • [quote author="Exotic_Devel" date="1414677565"]Two questions, where should I put these lines?[/quote]

    Anywhere in your source code. lupdate will find all words from your source code.

    [quote author="Exotic_Devel" date="1414677565"]What is context that should be passed to the QT_TRANSLATE_NOOP macro?[/quote]

    QPlatformTheme if you use Qt5, QDialogButtonBox if you use Qt4

    In other words copy & paste the code I've wrote anywhere in your source code and run lupdate, next open Qt linguist and translate the words/phrases and next lrelease the translation



  • bq. Anywhere in your source code. lupdate will find all words from your source code.

    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 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.



  • tr before you put the text?



  • [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



  • 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 ?



  • 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");
    ^



  • 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(...))



  • 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?


  • Lifetime Qt Champion

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



  • 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)!



  • 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



  • 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)!


  • Lifetime Qt Champion

    Do you have

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

    in the same folder as your executable ?



  • @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"



  • 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)!



  • 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)!



  • Saved and used again lrelease



  • Saved and used again lrelease



  • 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



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.