Unsolved How to change languages online?
-
Hello everyone,
I need some help.
I design a qt application. And it contains a lot of UIs. And there are many labels and buttons (and so on) whose text is changed by C++ code in some UIs. I want it to be international. So I need to translate to many languages. That's ok.
But I want to change languages online. I mean I hope it changes to the destination language immediately after I click change languages. I don't want to restart the application.
What should I? Could somebody give me some advices?I use Qt5.9.1.
Thanks in advance!
-
-
Hi,
You will have to create a method like
retranslate()
on every UI. Just set the text there usingtr()
.MyWidget::retranslate() { ui.label1->setText(tr("Translate text 1")); ui.pushButton1->setText(tr("Click it!")); ... }
Finally, on your mainWindow just call
retranslate()
on all of your UIs. -
-
Hi,
It seems that in new Qt versions, there is a
retranslateUi()
that the UIC creates automatically, so basically you have to load the QTranslator with the correct file and call theretranslateUi()
on all UIs.
For the items that do not belong to any UI, and so the UIC does not do the job for you, yes, you have to call do it manually.What some other softwares do is that it changes the language and restart the application with the help of QProcess.
-
@ollarch
OK. Thanks a lot!