1

I want to make translations on 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 file to property variant value. Main file:

/..
DynamicApp{
    id: statistics
    objectName: "Statistics"
    toolbarModel: ToolbarModel{}




    title:  qsTr("Statistics management")
    icon:   "qrc:/icons/statistics_128x128_w.png"
../

The DynamicApp is the qml file where is defined window of the app. There is defined toolbarModel which is "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 by qsTr or qsTranslate but I don't know how to cal it into property variant becouse there is calling into all file toolbarModel. Can you explain me how to translate this list in my app?

Grunthor
  • 93
  • 1
  • 10

1 Answers1

1

For the translations you need to add it into your APP.pro. You need to do a hack to add the QML translations so lupdate can actually 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, to include in the lupdate the qml files, we do a trick found on internet

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

After, run in console

lupdate NAMEOFPROFILE.pro

Now you will have generate the .ts including the ones for qml.

After doing your translation job, remember to

lrelease NAMEOFPROFILE.pro

Good luck!

David Sánchez
  • 544
  • 8
  • 21