Switch back to native language after install qm file by QTranslator
Unsolved
General and Desktop
-
I would like to switch back to native language after translation are done, but can't find a way to do it.
#include <QApplication> #include <QDebug> #include <QPushButton> #include <QTranslator> int main(int argc, char *argv[]) { QApplication app(argc, argv); QTranslator translator; translator.load("hellotr_la"); app.installTranslator(&translator); QPushButton hello(QPushButton::tr("Hello world!")); hello.resize(100, 30); QTranslator default_language; QObject::connect(&hello, &QPushButton::clicked, [&]() { static int removed = false; if(removed){ qDebug()<<"translator reinstall"; app.installTranslator(&translator); removed = false; }else{ qDebug()<<"translator removed"; removed = QCoreApplication::removeTranslator(&translator); //with or without this line, the result is same, the language never convert back to english app.installTranslator(&default_language); } }); hello.show(); return app.exec(); }
What is the proper way to do it?Thanks
-
See the solutions proposed here https://forum.qt.io/topic/92894/multi-language-application/8