PDA

View Full Version : Problem when translating my app



agent007se
31st July 2006, 18:20
Hi all !

I'm trying to translate my application. All is ok with the files which come from .ui . But with aller QMessageBox (just an exemple), I have a problem :

here's the main.cpp :


int main(int argc, char **argv)
{
...
else if(argc == 1)
{
// the translation is loaded in the contructor of ui_murefImpl (see below this code)
ui_murefImpl window(0, &app);
window.show();

// I'm doing this because I saw this in the ui.h file (and tr() && QApplication::translate() are too ineffective
QPushButton hello(QApplication::translate("MainWindow", "Music", 0, QApplication::UnicodeUTF8));
hello.resize(100, 30);
hello.show();

return app.exec();
}
....
}




ui_murefImpl::ui_murefImpl(QWidget *parent, QApplication *myApp) : QMainWindow(parent)
{
configure(myApp);
}

void ui_murefImpl::configure(QApplication *myApp)
{
// all that is correct because the ui is translated !
QTranslator translator;
QString locale = QLocale::system().name();
translator.load(QString("MuRef_") + locale);
myApp->installTranslator(&translator);
...
ui.setupUi(this);
...
}


The problem is that (of course) the text in the button is not translated (but I do correctly all the other manipulations : lupdate, qtlinguist (made changements, saved), lrelease and launching the program).


Thanks for reading ;) !

P.S.: I'm doing tests on a "hello button" because I don't want to recompile each time the whole app. But if it work on a QPushButton, it will still work with a QMessageBox...

jacek
31st July 2006, 19:11
tr() && QApplication::translate() are too ineffective
What makes you think so?


but I do correctly all the other manipulations : lupdate, qtlinguist (made changements, saved), lrelease and launching the program).
Can you see that button text when you open .ts file in Qt Linguist?

agent007se
31st July 2006, 19:31
What makes you think so?

For the best reason : I tested before asking ;) !



Can you see that button text when you open .ts file in Qt Linguist?
For sure I can (if not, how could I translate it since I use Qt Linguist ?).

Note : it appears in the context "MainWindow" and the source text panel is "Music" and I 'translated' it to "No music".

Edit :
this is a MINIMAL .pro file (I just want to translate the button, that will be a nice beginning :p !)


TEMPLATE = app
TARGET +=
DEPENDPATH += .
INCLUDEPATH += .

# Input
HEADERS +=
FORMS += muref.ui
SOURCES += main.cpp
TRANSLATIONS += MuRef_fr.ts



when I try with tr() I got this error :


main.cpp:23: error: `tr' undeclared (first use this function)
main.cpp:23: error: (Each undeclared identifier is reported only once for each function it appears in.)
:: === Build finished: 2 errors, 0 warnings ===

jacek
31st July 2006, 21:00
For the best reason : I tested before asking
And why it isn't effective?


it appears in the context "MainWindow" and the source text panel is "Music" and I 'translated' it to "No music".
Are you sure that your application loads the newest .qm file?


when I try with tr() I got this error :
tr() is a static method of QObject class.

QPushButton hello( QObject::tr( "Music" ) );

agent007se
31st July 2006, 22:30
And why it isn't effective?

Because it doesn't work in my case ! (and of course I have a problem because that's very useful functions... there's no doubt about this)


Are you sure that your application loads the newest .qm file?

How can I be ? There's only one .qm file and thus if it load the ui translation, it must load the others... (I don't really know about this).



tr() is a static method of QObject class.

QPushButton hello( QObject::tr( "Music" ) );

Correct ! I understood that while I was reading the chapter 15 (internationalisation) of the Qt 3 online book ;) !

edit : of course, I deleted the .ts and the .qm and made new ones to be sure that is a "proper" translation but that didn't change anything to my problem ! Do you need more source code or screenshots ?

jacek
31st July 2006, 22:39
Because it doesn't work in my case
Ah, OK. "too ineffective" == "doesn't work in my case"


There's only one .qm file and thus if it load the ui translation, it must load the others...
Then delete that file, start your application and check if no translation was loaded, create a new .qm file and check your application again.

agent007se
31st July 2006, 23:24
Ah, OK. "too ineffective" == "doesn't work in my case"

Yes I'm sorry English isn't my native language thus sometimes I may use some incorrect way of putting things togheter but I try to be at least readable ;).



Then delete that file, start your application and check if no translation was loaded, create a new .qm file and check your application again.

Ok I'll try that tomorrow ! (it's midnight here :p (Beligum))

Already thanks for trying to help me ;) that's not the first time :p !

jacek
31st July 2006, 23:28
I've just took another look on your configure() method. You create the translator on the stack, so it gets destroyed when configure() returns.

It should be:
void ui_murefImpl::configure(QApplication *myApp)
{
QTranslator *translator= new QTranslator();
...
translator->load(QString("MuRef_") + locale);
myApp->installTranslator( translator );
...
}

agent007se
31st July 2006, 23:43
I've just took another look on your configure() method. You create the translator on the stack, so it gets destroyed when configure() returns.

It should be:
void ui_murefImpl::configure(QApplication *myApp)
{
QTranslator *translator= new QTranslator();
...
translator->load(QString("MuRef_") + locale);
myApp->installTranslator( translator );
...
}

Yes yes yes !!! That works :D thanks a lot !