Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] centralized set of qml labels to use over multiple forms
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yazwas
    wrote on last edited by
    #1

    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.

    Thanks!

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        yazwas
        wrote on last edited by
        #3

        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?

        Thanks!

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          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.

          (Z(:^

          1 Reply Last reply
          0
          • Y Offline
            Y Offline
            yazwas
            wrote on last edited by
            #5

            Thank you!

            I will go with this solution as its simpler.

            Best regards

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved