Localization in QtQuick from top to bottom

After several weeks of on-off-off research, I still have not found a detailed guide on how to translate / localize in QtQuick (as in the case of using QML, not C ++ or Python).

In general, I ask what are the steps to properly localize a project, as much as possible in QtQuick, with minimal or preferably missing C ++.

In particular, there are a large number of holes that I need to fill in my understanding of how QtQuick handles localization.

So far I:

  • Added QT_TR_NOOP () to all my translation strings for translation at runtime

  • Added my file containing all the lines to my .pro file using lupdate_only {SOURCES + = LanguageStrings.qml}

  • Generated Translation Files Using QtLinguist

However, I intend to implement an option for dynamically changing the language, and the only example I saw regarding a translation that was not completely in C ++ essentially created an instance of the project for each language, rather than changing lines at runtime.

So how do I change the language at runtime? Is there a variable that I can set? Is it extracted from the system locale? I did not see a solid answer to this question.

Any ideas?

+4
source share
1 answer

You can do this with minimal C ++ (at least I think it is minimal). I did this in the past using the locale of the system on which the application is installed (right in main ()):

QGuiApplication app(argc, argv);

QTranslator translator;

if(translator.load(":/translations/myapp_" + QLocale::system().name())) {
    app.installTranslator(&translator);
} else {
    qDebug() << "Unable to load translation";
} 

. , QML (, ) . (https://wiki.qt.io/How_to_do_dynamic_translation_in_QML). , QML.

- , . Loader Element setSource . , , , (https://github.com/Conntac/qtExamples).

+2

Source: https://habr.com/ru/post/1679393/


All Articles