Multi Language Application



  • Is there a way to force re-translation after installing new translator?


  • Moderators

    Yes. If you are using QtWidgets, see the retranslateUi() that Qt Creator automatically adds to UI classes (if it still does).

    If you are using QML, then the (current) best solution is to create a global property (for example app.empty) and use it for all translatable strings, like so:

    Text {
      text: app.empty + qsTr("My string")
    }
    

    Then after installing the new translation all you need to do is to emit mptyChanged() signal. There is a better solution in the works, but it is not ready yet. Maybe in Qt 5.12 it will become available, I'm not sure. Well, it is available now, but it forces all bindings to be recalculated, so it is not a good thing at all.



  • I am using QWidgets but no UI file.
    actualy i made all my ui with layouts and styles so i didn't use UI.
    and retranslateUI funstion only works with UI files not QWidgets.

    what should i do in this case?


  • Moderators

    @mahd96 said in Multi Language Application:

    I am using QWidgets but no UI file.
    actualy i made all my ui with layouts and styles so i didn't use UI.
    and retranslateUI funstion only works with UI files not QWidgets.

    what should i do in this case?

    Write your own retlanslateUi() function. You can leanr about it C++ GUI programming book, for example (chapter "Making your applications translation aware").


  • Qt Champions 2017

    Hi
    Just as a note
    retranslateUi is not magical by any means. it just re-sets the text for u if created via designer.

    void retranslateUi(QMainWindow *MainWindow)
    {
    MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", nullptr));
    pushButton->setText(QApplication::translate("MainWindow", "load", nullptr));
    pushButton_2->setText(QApplication::translate("MainWindow", "save", nullptr));
    pushButton_3->setText(QApplication::translate("MainWindow", "clear", nullptr));
    }

    So to make your own, you just have to re-set any text you have.


  • Lifetime Qt Champion

    Hi,

    The technique to use is described in the dynamic translation part of Qt's translation documentation.



  • @mrjj i am talking about a project as big as Qt Creator itself!
    its not possible to reset every text!


  • Qt Champions 2017

    @mahd96
    Hi
    But sadly it is the only way if you want to do it live.
    So its much easier to require restart of restart app.


  • Lifetime Qt Champion

    Even for big projects, if you implement changeEvent for all your custom widgets, it's completely transparent.


Log in to reply
 

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