QObject::tr("%1").arg(_value);
Here _value is of QString type, which is dynamically generated. Is the above way correct to translate dynamically generated strings as in my code it doesn't seem to work.
There are two steps:
This means using one of
tr()
in a QObject subclassQCoreApplication::translate()
QT_TR_NOOP
/ QT_TRANSLATE_NOOP
lupdate
will extract the strings passed to those functions/macros, and make them available to linguist
for translation.
This is again done by tr()
and QCoreApplication::translate()
. So for instance:
// marking the strings for extraction
static const char *strings[] = {
QT_TRANSLATE_NOOP("MyContext", "hello"),
QT_TRANSLATE_NOOP("MyContext", "world");
};
// performing the translation at runtime
qApp->translate("MyContext", strings[0]);
There's a ton of documentation about the whole process, see here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With