Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Switch back to native language after install qm file by QTranslator

Switch back to native language after install qm file by QTranslator

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 298 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • thamT Offline
    thamT Offline
    tham
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      See the solutions proposed here https://forum.qt.io/topic/92894/multi-language-application/8

      (Z(:^

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved