[Interest] Language file resource loaded but UI not updating

Nicholas Yue yue.nicholas at gmail.com
Fri Apr 30 08:02:52 CEST 2021


Hi,

  I have a handler which responds to user language selection.

  I have map the index to load the correct language file but the UI remains
the same (no change to the text label)

  What function do I need to call to tell the application that I have
loaded a language file and to use it ?

void CMEForm::handleLanguageChange(int index)

{

    QLocale locale = ui_languageComboBox->itemData(index).toLocale();

    std::cout << "handleLanguageChange() called index = " << index <<
" locale = " <<
QLocale::languageToString(locale.language()).toStdString() <<
std::endl;


    // This may be the location where we can do the language/local swap/change

    {

        QTranslator translator;

        QString lang = QLocale::languageToString(locale.language());

        /*

        QString country = QLocale::countryToString(locale.country());

        */

        QString bcp47Name = locale.bcp47Name();

        QString langFile;

        if (bcp47Name == "en")

            langFile = QString(":/language/.qm/cme_gb.qm");

        else

            langFile = QString(":/language/.qm/cme_%1.qm").arg(bcp47Name);

        /*

        qDebug() << "START";

        qDebug() << "bcp47Name = " << bcp47Name;

        qDebug() << "locale = " << locale;

        qDebug() << "lang = " << lang;

        qDebug() << "country = " << country;

        qDebug() << "langFile = " << langFile;

        qDebug() << "END";

        */

        if (qApp->removeTranslator(&translator))

        {

            if (translator.load(langFile)) {

                qDebug() << "HELLO WORLD";

                bool installed = qApp->installTranslator(&translator);

                if (installed) {

                    loadLanguage("German");

                }

                qDebug() << "installed = " << installed;

                QString t = qApp->translate("Form", "German");

                qDebug() << "t = " << t;

                //return translator.translate("MainWindow", "English");

            }

        }


    }


}


Cheers
-- 
Nicholas Yue
Graphics - Arnold, Alembic, RenderMan, OpenGL, HDF5
Custom Dev - C++ porting, OSX, Linux, Windows
http://au.linkedin.com/in/nicholasyue
https://vimeo.com/channels/naiadtools
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210429/f003d749/attachment-0001.html>


More information about the Interest mailing list