Details
-
Suggestion
-
Resolution: Unresolved
-
P2: Important
-
None
Description
According to https://doc.qt.io/qt-6/qqmlapplicationengine.html#details,
- QQmlApplicationEngine automatically loads translation files from an i18n directory adjacent to the main QML file and the translation files must have "qml_" prefix e.g. qml_ja_JP.qm
- Translations are reloaded when the QJSEngine::uiLanguage / Qt.uiLanguage property is changed.
Example
project(QmlTranslationStudy VERSION 0.1 LANGUAGES CXX) find_package(Qt6 6.7 REQUIRED COMPONENTS Quick LinguistTools) qt_standard_project_setup( I18N_TRANSLATED_LANGUAGES de REQUIRES 6.7 ) qt_add_executable(appQmlTranslationStudy main.cpp ) qt_add_qml_module(appQmlTranslationStudy URI MyApp VERSION 1.0 QML_FILES Main.qml ) qt_add_translations(appQmlTranslationStudy)
Problem
The current rules in QQmlApplicationEngine do not align with the default structure produced by our current CMake API. The attached example would produce the following:
- :/qt/qml/MyApp/Main.qml
- :/i18n/QmlTranslationStudy_de.qm
- :/i18n/QmlTranslationStudy_en.qm
i.e. There is no "i18n directory adjacent to the main QML file", and the *.qm files don't start with "qml_".
Suggestions
Update the rules to look in ":/i18n" by default for *.qm filesAuto-search for *.qm files that are named after the current project? (although I'm not sure how the CMake project name could be passed to the engine at runtime)- Add CMake API to specifically add translations to a QML module and place them inside the module rather than at the root of the resource file system (something like a TRANSLATIONS argument to qt_add_qml_module or a separate qt_add_qml_translations function).
- Provide an API to configure the expected location(s) and prefixes of *.qm files (probably not necessary, though)
Side note
https://doc.qt.io/qt-6/qtranslator.html uses the word "prefix" a bit differently: For "qml_", "qml" is the filename while "_" is the prefix. Worth considering when we update our docs.
Attachments
Issue Links
- relates to
-
QTBUG-112857 Automatically merge translation files at build time
-
- Closed
-