Translate with tr() string defined with #define
-
wrote on 12 Jul 2017, 16:02 last edited by
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
-
Lifetime Qt Championwrote on 12 Jul 2017, 16:37 last edited by mrjj 7 Dec 2017, 16:40
@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]); }
-
wrote on 12 Jul 2017, 17:42 last edited by
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
-
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
Lifetime Qt Championwrote on 12 Jul 2017, 18:05 last edited by mrjj 7 Dec 2017, 18:21@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.
-
wrote on 12 Jul 2017, 18:28 last edited by
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
-
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
Lifetime Qt Championwrote on 12 Jul 2017, 18:30 last edited by mrjj 7 Dec 2017, 18:32- a variable redefinition.
You can fix that with extern.
in .h
extern const char* LT_FAMILY_NAME[] ;
and in .cpp (any)
const char* LT_FAMILY_NAME [] = {
QT_TRANSLATE_NOOP_UTF8("global","Lt\xE2\x84\xA2")
}; -
wrote on 12 Jul 2017, 20:52 last edited by Mwoua 7 Dec 2017, 20:53
Thats a good idea, I'll try it when I figure out how to write MC (a part of what im trying to translate) in superscript in title bar
4/7