PDA

View Full Version : Problem with dynamic translation



keo
28th July 2009, 14:54
Hi all,

I have a problem for dynamic translation. I am making a log system for an application and it must be international.

I have 2 kinds of log messages, with and without parameter.
Without parameter, the use of tr() fits perfectly.
But with parameters i keep having the original untranslated string, whereas the lupdate and lrelease worked perfectly (neither warning nor error).

Here is a sample of the code :


// The messages are stored in the constructor of the object (a singleton class)
Log::Log (){
// _message is a map where the strings are stored, declared in the .hpp file
map<unsigned int, QString>::iterator it = _message.begin();
_message.insert(it,pair<unsigned int,QString>(1,QObject::tr(" Missing parameter ")));
...
_message.insert(it,pair<unsigned int,QString>(51,QT_TR_NOOP(" Example message with %1")));
_message.insert(it,pair<unsigned int,QString>(53,QT_TR_NOOP(" Message2 with %1 and %2")));
...
}



In the same class I have a convert(int,list<QString>) function that takes a number and possible parameters and it returns the corresponding string :



QString Log::convert(int numMsg, list<QString> param) {
map<unsigned int,QString>::iterator it = _message.begin ();
// If there are parameters
switch (param.size ()){
case 0 :
return _message.find (numMsg); // Returning the corresponding string
break;
case 1 :
// Function that finds the corresponding message with 1 parameter
return fill1(param,it);
break;
case 2 :
....

}

}



And the fill1() function that is in the Log class too and that must perform the translation :



QString Log::fill1 (list<QString> param, map<unsigned int,QString>::iterator it) {
list<QString>::iterator iter = param.begin ();
return QObject::tr ((*it).second.toLatin1 ()).arg(*iter);
}



It works fine with the english version, but when i load a translator, the strings translated using the QT_TR_NOOP macro are still in english.
Assuming i have neither warning nor error in QLinguist, and the number of translated sentence with lrelease corresponds exactly to the number of sentence i have, does anyone have an idea why the right sentences are not found ?

I used a local map in the fill1 () function to try but it remained the same, i tried QT_TRANSLATE_NOOP () with context but nothing changed.




.

caduel
29th July 2009, 11:04
QT_TR_NOOP is only a marker for the linguist tools. If your string shows up in linguist, that part was ok.
If english translations work, and others do not, you should check if the translator for the other language was really loaded successfully.

keo
29th July 2009, 11:36
Thanks for your reply but the load is successful because the other strings are translated, only the one passing through QT_TR_NOOP and later tr() remain in English.
It is not English translation works and other don't, but the soft is made in English, and there is no problem with english messages, but when i want to translate it to another langage there is a problem.

But the problem has just been solved thanks to a friend.
I have to make my class inherit from QOBJECT, use the Q_OBJECT macro, and do not use QObject::tr() but tr() to be in the right context.