View Full Version : tr with #define..it can work?
mattia
31st January 2008, 10:15
Hello, im my default.h i put:
#define aString "aString";
if i want to use aString as a QString in my project i used to do in this way
...
QString ( aString )
...
but if i want internazionalizzate it with "tr()" function what should i do?
i tried with tr
tr ( QString ( aString ) )
but i get this error
main.cpp:4396: error: no matching function for call to ‘main::tr(QString)’
thx
marcel
31st January 2008, 10:27
The tr signature is QObject::tr ( const char * sourceText, const char * comment = 0, int n = -1 ) .
So you can just pass aString:
QString translated = tr(aString);
mattia
31st January 2008, 11:34
good, now i don't get any error...but i did
lupdate project.pro
lrelease project.pro
i can't find the voice in my .ts file...
bender86
31st January 2008, 11:56
From http://doc.trolltech.com/4.3/i18n.html#use-tr-for-all-literal-text:
If you need to have translatable text completely outside a function, there are two macros to help: QT_TR_NOOP() and QT_TRANSLATE_NOOP(). They merely mark the text for extraction by the lupdate utility described below. The macros expand to just the text (without the context).
Gopala Krishna
31st January 2008, 17:25
Why don't you do it this way ?
const QString astring = QObject::tr("astring"); // global or wrapped in singleton class
mattia
1st February 2008, 11:04
Why don't you do it this way ?
const QString astring = QObject::tr("astring"); // global or wrapped in singleton class
in this way i get a error
error: ‘QString’ does not name a type
jpn
1st February 2008, 11:14
in this way i get a error
error: ‘QString’ does not name a type
Did you include <QString>?
Btw, bender86 already pointed out the correct way to do it if you insist using defines.
mattia
4th February 2008, 08:52
Hi, i did as bender86 suggest, i added in my default.h this:
static const char *greeting_string = QT_TR_NOOP("Hellooooo");
and in my*ts file i translated greeting_string,
<message>
<location filename="../default.h" line="47"/>
<source>Hellooooo</source>
<translation>Ciaooooooooooooooo</translation>
</message>
but when i call tr(greeting_string) in my application i'm not able to see greeting_string translated...I can just read "Hellooooo".
With other QString in my application i I have not problem to see them translated.
Any hint?
thx
jpn
4th February 2008, 09:03
You must use QT_TRANSLATE_NOOP() outside class context. QT_TR_NOOP() is used inside class context.
mattia
4th February 2008, 11:15
thanks so much now it correctly works, but when i compile my application i keep having this annoying massage:
default.h:48: warning: ‘greeting_string’ defined but not used
greeting_string is declared in this wy:
static const char *greeting_string = QT_TRANSLATE_NOOP( "mainWindow" , "Hello" );
and it's used in mainWindow.
thx
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.