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:
Example of implementation of getMyString():
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.
|For Gerrit Dashboard: QTBUG-102393|
|457332,12||qml/i18n: Mention LanguageChange event for C++ types||dev||qt/qtdoc||Status: MERGED||+2||0|
|457349,1||QQuickItem: Propagate language and locale change to non-item children||dev||qt/qtdeclarative||Status: ABANDONED||0||0|
|459080,2||qml/i18n: Mention LanguageChange event for C++ types||6.5||qt/qtdoc||Status: MERGED||+2||0|
|473203,3||QQmlEngine: Introduce markCurrentFunctionAsTranslationBinding||dev||qt/qtdeclarative||Status: MERGED||+2||0|