Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
QDS 4.6.0
-
None
Description
<Issue>
i18n folder which contains .ts files must reside in the same folder where the initially loaded .qml file is located. Otherwise, i18n doesn't work and the texts with translation APIs such as qsTr() are not translated at all.
<Proposal>
Add a section in the documentation (https://doc.qt.io/qtdesignstudio/studio-translations.html) about the necessary steps to be taken in order to make i18n work for the launched application with Run button.
Here are several points to cover. If anything is missing, please add them too.
--------------------
How to enable your translations for Run Project
In this section, we will explain how to enable your translations for the application launched from Qt Design Studio with Run Project button.
(1) Qt Design Studio must be aware of the QML files(Here, "QML files" means files whose file extention is either .qml or .ui.qml) with translatable texts, which are the texts enclosed with qsTrId(). Otherwise, it won't generate .ts and .qm files out of them when you press "Generate Qt translation source files (.ts) and compiled binary files (.qm) for the whole project" in the Translations view.
It means that you must add the directory which contains QML files with qsTrId() to QmlFiles entry in the project's root .qmlproject file, like so:
QmlFiles { directory: "MyQMLDir" // MyQMLDir contains a .qml file with translation API(s). }
This makes Qt Design Studio recognize the QML files inside this MyQMLDir directory.
Here, MyQMLDir doesn't necessaliry have to be a QML module, meaning, it doesn't have to contain qmldir file with module definition inside.
(2) i18n directory is generated at the project's root directory, when you press "Generate Qt translation source files (.ts) and compiled binary files (.qm) for the whole project." Howerver, the generated i18n folder must be inside a directory in which the initially loaded QML file resides, which is by default, App.qml. When you create a project(expcet for Qt for MCUs project, as of Qt Design Studo 4.6.0), Qt Design Studio creates a folder named <Project Name>Content, in which App.qml is located. This means that, currently you have to manually copy(doesn't have to be "cut") and paste the updated i18n directory from the project's root directory into the <Project Name>Content diectory where App.qml resides. This is a known issue in Qt Design Studio and will be addressed in the future release.
(3) With these setup, you can see that the translation ids are translated based on your development machine's locale, when you run the application from Qt Design Studio. Here, "run the application" means when you press a green rectangle button named "Run Projcet."
(4) You can change the language to apply during runtime, by changing the value of Qt.uiLanguage.] Here's an example.
Button { id: button text: "Button" Connections { target: button function onClicked() { // switch between Japanese and English every time the button is clicked. Qt.uiLanguage = Qt.uiLanguage === "ja" ? "en" : "ja" } } }