Raviteja
Raviteja

Reputation: 96

Dynamic changing of Language in QML view

In my project, there is a language page with four language options. If we change them, entire application language and some images changes. My problem is is there any signal/ callback to switch resources as like in Android or any some other mechanism we should follow for this QML?

Upvotes: 2

Views: 2728

Answers (1)

NG_
NG_

Reputation: 7181

To do what you need, first, get familiar with official documentation on Internationalization and Localization with Qt Quick.

Next you need to wrap all strings that should be translated into qsTr. Then, here is simplified code of switching languages:

void Settings::switchToLanguage(const QString &language)
{
    if (!m_translator.isEmpty())
        QCoreApplication::removeTranslator(&m_translator);
    m_translator.load(QStringLiteral(":/language_") + language));
    QCoreApplication::installTranslator(&m_translator));
    m_engine->retranslate();
}

According to article New in Qt 5.10: Dynamic Language Change in QML.

Upvotes: 3

Related Questions