Is there a way to use Linguist in Global context?



  • Hi,

    I need all string translations in all files. Is there a way to accomplish this in QML?

    Thanks


  • Moderators

    What do you mean? lupdate will return you a TS file with all strings, both c++ and QML ones.

    You may need to use a .pro file hack to get it working, though:
    @
    lupdate_hack{
    SOURCES +=
    path/to/qml.qml
    path/to/qml2.qml
    }
    @

    This adds qml files to sources in view of lupdate, but does nothing in qmake's eyes. So your project will still compile, and all translations will be taken into account.



  • Thank you for the reply.

    I have already used the hack. And i am doing dynamic translation. Unfortunately I cannot use the approach suggested in "http://qt-project.org/wiki/How_to_do_dynamic_translation_in_QML":http://qt-project.org/wiki/How_to_do_dynamic_translation_in_QML since it will ultimately end in something like:

    main.qml
    @
    MyComponent{
    id: schnidee
    text: qstr("Schmext") + translate.getEmptyString()
    }@

    I want the user to be able to edit everything in design mode. But done like shown above he will see #qstr("Schmext") + translate.getEmptyString()# instead of "Schmext" in the editor.Secondly the translate functionality will not be automatically included if he drags MyComponent onto the canvas.

    So what i did is emit a languageChanged() signal to all MyComponents in C++ and catch it in QML by:

    MyComponent.qml
    @FocusScope{
    ...
    property string myCompText
    Text{
    signal languageChanged()
    id: subtext
    text: myCompText
    onLanguageChanged: text= qstr(myCompText)

    }
    ...
    }@

    Trouble is, the translation of the text the user thinks is in main.qml will actually be done in MyComponent.qml. And requiring the user to do complicated QtLinguist stuff to work around this is not my intention either.

    Since the overall amount of text will be rather small I could live with a global Translation. I want to get rid of the Context in QtLinguist or something like that. All translations may well be available in one global context.

    Thanks


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.