Translation at runtime (dynamic translation)
-
I have a screen to pick the language for the app.
I understand that I need to callapp.removeTranslator()
and thenapp.installTranslator();
on the language switch, and then listen toQEvent::LanguageChange
to retranslate.
But the problem is I don't have access toapp
in that screen:int main(int argc, char *argv[]) { QApplication app(argc, argv); //app is declared here QTranslator translator; translator.load("myApp_en"); app.installTranslator(&translator); LoadingScreen loadingScreen; loadingScreen.showWindow(); return app.exec(); }
And I need to change the language from another class, which inherits from
QMainWindow
. All widgets are created dynamically in code. For example:title = new QLabel(); title->setText(tr("Choose Language"));
So can someone tell me please how can I install a new translator from this other class?
Thanks
-
hi
there is qApp that works in all application. -
@AlaaM ¨
Hi I think you can have multiple translators(file) active, so when you switch language
its best to remove old one or it might get messy as the old one would also be searched.
But if completely different language, i doubt anything crazy will happen.http://www.informit.com/articles/article.aspx?p=1405555&seqNum=3