Unsolved Qt translation get original string
-
Hi,
I want to log a message without translating it and also I want to display translated message to user. Is it possible to achieve this and at the same time register the string to Qt translating system?Bad - This causes message not to be registered by Qt translating system:
QString message = "Message"; log(message); showMessageToUser(tr(message));
Bad - This duplicates the string
log("Message"); showMessageToUser(tr("Message"));
Bad - This logs translated version of the message - I want non translated.
QString message = tr("Message"); log(message); showMessageToUser(message);
-
@MartinD
As far as I know, the second "bad" is the least bad of all as it actually works. I think you're stuck with it. -
It's not as convenient as the
tr()
function but you can use the QT_TRANSLATE_NOOP macro for this. For example:void logIt(const char* str) { log(str); showMessageToUser(qApp->translate("", str)); }
Use it like this:
logIt(QT_TRANSLATE_NOOP("", "Hello world!"));
-
@Chris-Kawa That works well in both c++ and qml. Thanks