PDA

View Full Version : Translating a QStringList



^NyAw^
17th January 2007, 17:36
Hi,
Is there anyway to transalte the contents of a QStringList automatically without have to transtale every QString item?

I have a QStringList with a number of QStrings that have to be translated (I have the translator installed and the texts are translated). I'm using the "QTableWidget::setHorizontalHeaderLabels ( const QStringList & labels )" method. Is there a way to to this without having to get all the QStrings, transale them an put them into another QStringList ?

Thanks,

wysota
17th January 2007, 17:39
Is there anyway to transalte the contents of a QStringList automatically without have to transtale every QString item?
No, there isn't. You can only use a trick such as this:


QString str=tr("name,address,telephone number");
QStringList slist = str.split(",");

^NyAw^
17th January 2007, 18:09
Hi,
mmm, I think that you don't have understood me.

In my QStringList there are i.e. 4 QStrings: "Area", "Center X", "Center Y", "Radius".
I insert this QStringList as Horitzontal Header of a QTableWidget with the method "setHorizontalHeaderLabels" that takes a QStringList. I would to have the 4 items translated into the QStringList without having to do a bucle. The solution is easy:



for (int i=0; i<qlist.count(); i++)
{
qtranslatedlist.insert(i,tr(qlist[i])); //Or something like this
}


So, I would know if there is a method to translate all the QStrings with only one function.

Thanks,

wysota
17th January 2007, 18:22
mmm, I think that you don't have understood me.
Yes, I have :)


So, I would know if there is a method to translate all the QStrings with only one function.

If you require those strings to be separate, then no. But if it's not that necessary (and I think it's not), then you can use the method I suggested - put all labels into a single string, translate the string (in one go) and then split it into a string list.

jacek
17th January 2007, 22:35
I would know if there is a method to translate all the QStrings with only one function.
Yes, there is a way --- write such function yourself:

QStringList Utils::tr( const QStringList & list )
{
QStringList result;
foreach( const QString & str, list ) {
result << QObject::tr( str );
}
return result;
}

Other solution is to translate those strings before you add them to that list.

^NyAw^
18th January 2007, 12:06
Hi,
Ok, thanks for replies.