Nominate our 2022 Qt Champions!

Translations in QML files

  • Hi there,

    I have problems with translations (using function qsTr()) in my QML file which is loadad as component into anther QML file.
    I created standard "Hello world!" project in QtQuick. The MainPage.qml file created by Qt Creator is being loaded into main.qml file as a component for initialPage. Here are the codes:

    @import QtQuick 1.1
    import 1.1

    PageStackWindow {
    id: window
    initialPage: MainPage {tools: toolBarLayout}
    showStatusBar: true
    showToolBar: true

    ToolBarLayout {
        id: toolBarLayout
        ToolButton {
            flat: true
            text: qsTr("Back")
            iconSource: "toolbar-back"
            onClicked: window.pageStack.depth <= 1 ? Qt.quit() : window.pageStack.pop()



    @import QtQuick 1.1
    import 1.1

    Page {
    id: mainPage
    Text {
    anchors.centerIn: parent
    text: qsTr('Hello world!')
    color: platformStyle.colorNormalLight
    font.pixelSize: 20

    Problem is that "Back" in main.qml is translated correctly (after all necessary steps with lupdate and linquist resp. lrelease) but "Hello world!" from MainPage.qml does not translate at all.

    NB of course I performed manual loading of QTranslator and istallation in main.cpp file like this:
    @ QTranslator* translator = new QTranslator;

    qDebug()<<"Translating: "<<translator->load(QString("qml/International/inter_sk"));

    Like this:
    ! translation problem)!

    So I think when loading component from QML file then the translation is not working.

    Any guesses why? experiences????
    Thanks a lot

    Translation files need to be prepared case sensitively:

    lupdate mainpage.qml -ts inter_sk.ts is wrong
    lupdate MainPage.qml -ts inter_sk.ts is correct

  • Hi,, I stuck in same problem did you solve it,?

Log in to reply