PDA

View Full Version : Internationalization with Qt



vermarajeev
16th November 2006, 08:54
Hi guys,
I'm working with a sample program, where I need to make my application translated to other language other than English. I went through Qt linguist manual and followed the steps for translation.

Can you guys tell me why m not able to convert the english text to french
Here is my sample program

--------------------------------------------------------------------------------------------------
//myfile.h

class ArrowPad : public QWidget
{
Q_OBJECT
public:
ArrowPad(QWidget *parent=0, const char *name="ArrowPad" );
~ArrowPad(){}
private:
QPushButton* up;
QPushButton* left;
QPushButton* right;
QPushButton* down;
};

class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent=0, const char *name="MainWindow" );
~MainWindow(){}

private:
QPopupMenu * file;
};

------------------------------------------------------------------------------------------------------
//myfile.cpp

ArrowPad::ArrowPad(QWidget *parent, const char *name)
: QWidget(parent, name)
{
up = new QPushButton(tr("&UP"), this) ;
up->setGeometry(200, 100, 40, 40);

left = new QPushButton(tr("&LEFT"), this) ;
left->setGeometry(150, 140, 40, 40);

right = new QPushButton(tr("&RIGHT"), this) ;
right->setGeometry(250, 140, 40, 40);

down = new QPushButton(tr("&DOWN"), this) ;
down->setGeometry(200, 180, 40, 40);

}

MainWindow::MainWindow(QWidget *parent, const char *name)
:QMainWindow(parent, name)
{
file = new QPopupMenu(this);
menuBar()->insertItem( tr("&File"), file);
file->insertItem( tr("E&xit"), qApp, SLOT(quit()),
tr("Ctrl+Q", "Quit") );
ArrowPad *ap = new ArrowPad( this, "arrow pad" );
setCentralWidget(ap);
resize(500, 500);
}
------------------------------------------------------------------------------------------------------
//main.cpp

#include <qapplication.h>
#include <qpushbutton.h>
#include <qtranslator.h>
#include <qtextcodec.h>
#include "test.h"


int main( int argc, char **argv )
{
QApplication app( argc, argv );

MainWindow mw;

QTranslator translator( 0 );
translator.load( "tt2_fr", "." );
app.installTranslator( &translator );

app.setMainWidget( &mw );
mw.show();
return app.exec();
}

I have also created *.ts and *.qm files using lupdate and lrelease but still the program shows me english text. I have taken this sample from Qt linguist manual, section->Programmers

Any comment will be highly appreciated
Thanx

jpn
16th November 2006, 09:11
What does QTranslator::load() return?

vermarajeev
16th November 2006, 09:22
What does QTranslator::load() return?

Hi thankx for your reply,
I have just added this code in my main.cpp


bool flag = translator.load( "tt2_fr", "." );
if(flag)
qDebug("File loaded successfully");
else
qDebug("Failed");

This returns true and displays File loaded successfully.

Thankx

wysota
16th November 2006, 09:57
Load the translator before creating the window or provide support for language change event for the window.

vermarajeev
16th November 2006, 10:18
Load the translator before creating the window or provide support for language change event for the window.

Hi, Can you please explain with an example as I'm unable to get you.

vermarajeev
16th November 2006, 10:22
Hi, Can you please explain with an example as I'm unable to get you.

hey Thankx it works,
I loaded the translator before creating the window

Thankx a lot,