Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-102393

QQmlEngine::retranslate no longer retranslates strings coming from C++

    XMLWordPrintable

Details

    • 98504f2c9 (dev), b097fb6dc (6.5), 59567e25f (dev)

    Description

      Hi,

      Following fix of QTBUG-96192 (https://codereview.qt-project.org/c/qt/qtdeclarative/+/375491), QQmlEngine::retranslate properly reevaluates QML bindings, leading to their re-translation, but cannot detect translated strings coming from C++, leading to a regression compared to previous versions.

      An example of binding that was working dynamically before the change of behavior:

      Text {
          function textForThing()
          {
              return handler.getMyString();
          }
          anchors.centerIn: parent
          text: textForThing()
      }
      

      Example of implementation of getMyString():

      class Handler : public QObject
      {
          ...
          QString getMyString() const
          {
              return QObject::tr("This is a test");
          }
      };
      

      For this case, we have no way to force the reevaluation of everything, so we would have to rely on the trick of "+ emptyString" on all texts to have them update themselves each time there is a re-translation.

      Please note that in the example above, I'm using QObject::tr(), but I could for example have written myTexts[getCurrentLang()] instead (with myTexts loaded from JSON configuration files). I mean that C++ will not always rely on QObject::tr(): it just expects to be called from QML bindings each time lang changes.

      I attached a small test project to reproduce the issue: clicking on the window with Qt 5.15.2 leads to a re-translation, while with Qt 6.3.0 RC, it no longer does.

      Not sure what we can do? To be honest, I'm very impacted by this change of behavior because I have a lot of strings coming from C++, so I liked very much the previous behavior, even if that would reload more than required.

      Thank you,
      Louis

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            fabiankosmale Fabian Kosmale
            amnell Louis du Verdier
            Votes:
            0 Vote for this issue
            Watchers:
            12 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes