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. translate in qml and C++
Forum Updated to NodeBB v4.3 + New Features

translate in qml and C++

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 780 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.
  • P Offline
    P Offline
    Pueablo
    wrote on last edited by
    #1

    Hello good day, I have a question about what is happening to me, I am using a QML application that receives the label texts from C++, and I want to translate these texts, I apply my .ts and .qm file and only the QML texts are translated ( I added qsTr("text")), in C++ I have placed tr and QT_TR_NOOP but none sends me the translated, my labels are in their original language. What could I do? Thank you very much for your time and have a nice day!!!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      How are you changing the language of your application.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Pueablo
        wrote on last edited by
        #3

        hello, in C++ I do it with tr("text to translate") and in qml I do it with qsTr("text to translate"). The .ts file does detect the text for me, only that when applying the translation the text is in the original language.

        Something to add is that I added the text to a component in C++ and then send it to QML to print.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          That does not answer my original question, when/how are you loading the translator ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Pueablo
            wrote on last edited by Pueablo
            #5

            sorry, in the main.cpp file followed by "QQmlApplicationEngine engine;"

            QQmlApplicationEngine engine;
            QTranslator _translator;
            _translator.load(":/traducciones/ingles");
            app.installTranslator(&_translator);

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by SGaist
              #6

              Did you already check this example ?

              The translation handling is not the same between Qt Quick and pure C++ applications.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Pueablo
                wrote on last edited by
                #7

                Hello, in case it helps someone in the future, I was able to solve it by changing the way of installing the translation, since I have several classes and it was not applied to any of them.
                I changed the app.installTranslator(&_translator);
                by: QCoreApplication::installTranslator(&_translator);

                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