PDA

View Full Version : Linguist and static strings



Equilibrium
4th March 2008, 14:06
Hi All ,

I need to translate my application , everithing worked fine, till i had to translate static string array.

I have a ".h" file with this decleratrion


static QString vecBombType[4] = {
QObject::trUtf8("None"),
QObject::trUtf8("Explosive"),
QObject::trUtf8("Flare"),
QObject::trUtf8("Smoke")
};

I'm inserting those string into QComboBox in a .cpp file

for ( int i=0; i < 4 i++ )
{
cboxBombType->insertItem( vecBombType[i], i);
}
I've translated "Explosive" to something else , but keep on getting "Explosive" string.

Beside this all translation are OK.

How can i fix this?

bender86
4th March 2008, 14:21
Because static variables are initialized before main function is called, long before you load translators. You should have a function that initializes that array after translators are loaded.

EDIT
Or, you could use trUtf8 when using that strings. I'm not sure, but it may work.


static QString vecBombType[4] = {
QObject::trUtf8("None"),
QObject::trUtf8("Explosive"),
QObject::trUtf8("Flare"),
QObject::trUtf8("Smoke")
};

...

for ( int i=0; i < 4 i++ )
{
cboxBombType->insertItem( trUtf8(vecBombType[i]), i);
}

wysota
4th March 2008, 14:32
static QString vecBombType[4] = {
QT_TR_NOOP("None"),
QT_TR_NOOP("Explosive"),
QT_TR_NOOP("Flare"),
QT_TR_NOOP("Smoke")
};

for ( int i=0; i < 4 i++ ){
cboxBombType->insertItem( tr(vecBombType[i]), i);
}

Equilibrium
4th March 2008, 14:49
tried , didn't work
the static string is in a different header , i've placed it inside the project , ts file include this strings.
Translating , releasing

still same issue

Equilibrium
4th March 2008, 14:50
didn't work, bender ,thanks

wysota
4th March 2008, 15:27
If it's in a different header then you have to pass the context to translate() and QT_TR_NOOP(). Or move those strings into the same context.

jpn
4th March 2008, 15:30
Just look at QT_TRANSLATE_NOOP() (http://doc.trolltech.com/4.3/qtglobal.html#QT_TRANSLATE_NOOP) and QT_TR_NOOP() (http://doc.trolltech.com/4.3/qtglobal.html#QT_TR_NOOP) docs. They are very well documented and include clear examples.

Equilibrium
5th March 2008, 13:08
founf what to do thanks to every one