Translate with tr() string defined with #define
-
Hello,
I have a string defined with #define str, and I need to translate it, but not everywhere.The #define is in a separate file LtDefs.h :
#define LT_FAMILY_NAME "Lt\xE2\x84\xA2" //TM utf8 code
and in certains classes, I need to translate it. I've tried to use
tr(LT_FAMILY_NAME ) but it doesnt add the string to translation list.
The class has the Q_OBJECT macro, but not the LtDefs.h
Is there a way to translate a string defined with #define ? I've seen the QT_TR_NOOP macro, but I dont really understand it
-
@Mwoua said in Translate with tr() string defined with #define:
QT_TR_NOOP
Hi
As far as I remember it would NOT pick up defines for translation.
It seems to be looking for tr("") and no other form except ""
Make sense that lupdate cannot see variables / defines as its not via the compiler.one way is to use a function
QString FriendlyConversation::greeting(int type) { static const char *greeting_strings[] = { QT_TR_NOOP("Hello"), QT_TR_NOOP("Goodbye") }; return tr(greeting_strings[type]); }
-
My problem is that the #define is in a header included in several place in the code, so I can't replace it by a function easily
@Mwoua
Well there is no way to get it to grab the #define.Also, it will not get translated anyway, as the tr() macro is key to make it work.
So even if you add it manually to the translation file.
It will not work when you load a new language.It does not have to be a function.
This also worksconst char* LT_FAMILY_NAME [] = { QT_TRANSLATE_NOOP_UTF8("global","Lt\xE2\x84\xA2") };
qDebug() << LT_FAMILY_NAME;
Should work instead of the #define with no altering code.
-
My header is included in several place, so it gives me a variable redefinition. I dont think there is an easy way to get this to work, so I've an ugly workaround