Important: Please read the Qt Code of Conduct -

[SOLVED] centralized set of qml labels to use over multiple forms

  • Good day

    I have somewhat strange request :)

    We are developing a qml application that has multiple forms. for example some forms will have "first name", "last name", "prefix" .... labels.

    What we want is a way to support translation, but not to translate every occurrence of every label in every form.

    Is there a way to have something like a central set of labels that we define and use them in the forms and when we translate only those labels, the effect will be show on all the forms that uses them.

    I hope the explanation is clear, and any suggestion is more than welcome.

    If you have implemented this anyway differently, please let me know how you did it.


  • Moderators

    Just create a new Qml file for every label you want, then include it in your app. Every instance will be using the same base file, and will share it's translation.

    Or another possibility would be to create a "translation object" that holds all strings, is translatable, and the generic labels in your app access that object's strings to show them to the users.

  • Thank you Sierdzio

    What do you mean by translation object? a C++ class for example where we export the values to qml objects or a QML object?


  • Moderators

    I think something like this would suffice, although it might be a bit suboptimal, now that I think about it:
    TranslationObject {
    property string myText1: qsTr("Blah")
    property string myText2: qsTr("Blah2")
    // ... etc.

    // Your UI:
    TranslationObject { id: translation }
    Label {
    text: translation.myText1

    Exporting from C++ is also an option, of course.

  • Thank you!

    I will go with this solution as its simpler.

    Best regards

Log in to reply