How to make qml translations

I want to make translations in my toolbar. The toolbar is a listmodel:

import QtQuick 1.1 ListModel { id:tBar ListElement { buttonText: QT_TR_NOOP("Cars In Speed Function") bottomText: "" event: "carsInSpdFn" buttonLevel: "0" buttonBurst: false icon: "qrc:/icons/histogram_128x128_w.png" color: "#369c3b" active: true permissionLevel: 0 } ListElement { buttonText: QT_TR_NOOP("Clear all logs") bottomText: "" event: "cleraAllLogs" buttonLevel: "0" buttonBurst: false icon: "qrc:/icons/trash_128x128_w.png" color: "steelblue" active: true permissionLevel: 3 } 

The list is called in the file in the property value. Main file:

 /.. DynamicApp{ id: statistics objectName: "Statistics" toolbarModel: ToolbarModel{} title: qsTr("Statistics management") icon: "qrc:/icons/statistics_128x128_w.png" ../ 

DynamicApp is a qml file that indicates the application window. A toolbarModel is defined, which is a "property variant". DynamicApp:

 /.. Rectangle { id: app width: main.width height: main.height color: layout_id.bgColor opacity: 0 property variant parameter; property bool useToolbar: true property bool useTopbar: true property bool activeApp: false property variant toolbarModel property string title: "" property string icon: "" ../ 

I know how to translate model lists using qsTr or qsTranslate, but I don’t know how to put it in a property variant, because there is a call to the entire toolbarModel file. Can you explain to me how to translate this list into my application?

+1
source share
1 answer

For translations you need to add it to your APP.pro. You need to hack to add QML translations so that lupdate can really reach them. For example, in our project we have:

 # English TRANSLATIONS += settings/language/set_language/setting_en.ts # Spanish TRANSLATIONS += settings/language/set_language/setting_es.ts 

After including qml files in lupdate, we do the trick found on the Internet

 evil_hack_hahaha_add_what_ever_you_want_etc { SOURCES += path_to_qml/*.qml \ path_to_qml2/*.qml \ ... } 

After starting in the console

 lupdate NAMEOFPROFILE.pro 

Now you will generate .ts, including for qml.

After completing the translation job, remember

 lrelease NAMEOFPROFILE.pro 

Good luck

+1
source

All Articles