QT_TRANSLATE_NOOP inside static const QMap?
-
Hi
Yes this marks them for extraction by the lupdate tool.You need a call to tr() to translate it.
QString FriendlyConversation::greeting(int type) { static const char *greeting_strings[] = { QT_TR_NOOP("Hello"), QT_TR_NOOP("Goodbye") }; return tr(greeting_strings[type]); <<<<<<< returns via tr() }
-
How do you load the translation ?
https://wiki.qt.io/How_to_create_a_multi_language_application -
@mrjj said in QT_TRANSLATE_NOOP inside static const QMap?:
How do you load the translation ?
https://wiki.qt.io/How_to_create_a_multi_language_applicationi'm exactly loading the translation this way. It work's very well with my other translations, for example the Menu-Entries or other QLabel on which i directly call tr(VALUE). But not the one i posted. Could it be problemativ because i declare and initialize it outside the class?
But i found no other way to declare and initialize a static const variable.I did some research and found ouut that:
When i call qDebug() << qApp->translate( "OrderForm2", flowers[0] );
instead of qDebug() << tr(flowers[0]); i got the translated content.But i did it not work without calling qApp->translate() ?
-
@Opa114
Well you are using it with a context ("OrderForm2")
and the sample for that actually use app transstatic const char *greeting_strings[] = { QT_TRANSLATE_NOOP("FriendlyConversation", "Hello"), QT_TRANSLATE_NOOP("FriendlyConversation", "Goodbye") }; QString FriendlyConversation::greeting(int type) { return tr(greeting_strings[type]); } QString global_greeting(int type) { return qApp->translate("FriendlyConversation", <<<< context greeting_strings[type]); }
So it could be related to that. ( context)
-
-
@Opa114
Well when not in an object, the context is different, so
I guess that's why to specify one, makes it work.
Well just use what works, it all ends up being the same type
of lookup in a table so TR or qApp->translate should not matter much.