Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Is there a way to use Linguist in Global context?

    Tools
    2
    3
    1563
    Loading More Posts
    • 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.
    • A
      alexander.merkel last edited by

      Hi,

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

      Thanks

      1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        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.

        (Z(:^

        1 Reply Last reply Reply Quote 0
        • A
          alexander.merkel last edited by

          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

          1 Reply Last reply Reply Quote 0
          • First post
            Last post