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?
Asked
Active
Viewed 1,870 times
2
-
1read https://doc.qt.io/qt-5/qtquick-internationalization.html – eyllanesc May 13 '19 at 05:42
-
1There is a tutorial in the Qt wiki explaining how to achieve this : https://wiki.qt.io/How_to_do_dynamic_translation_in_QML Hope this helps. – A.LeBreton May 13 '19 at 12:30
1 Answers
3
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.

NG_
- 6,895
- 7
- 45
- 67