PDA

View Full Version : A problem about i18n



FinderCheng
16th October 2009, 02:00
Hi, there! I have a problem about i18n.

I have added
TRANSLATIONS += resources/locale/pw_zh_CN.ts

into .pro file and use lupdate and linguist tools to get .qm file. Then I use the following code to install translators on my application:

QTranslator appTranslator;
qDebug() << appTranslator.load("../resources/locale/pw_zh_CN");
qApp.installTranslator(&appTranslator);


OK, the qDebug() output true which means Qt has successfully load .qm file. But when I tried to run my application, there were still original english words that defined in tr() on UI. I don't know why.

I have tried to create a new project and do this as I said. It can translate this test window. I'm using QtCreator IDE.

I really don't know why this happen, could you tell me how to solve this problem?

Thank you!

=========================
PS: I have fixed this problem. It is because I use
using namespace XXX;

instead of
XXX::AppCass::foo()

in *.cpp files. But I still have a problem: only in one dialog it cannot translate, others are OK...

Lykurg
16th October 2009, 08:10
Hi,

there is a difference between [ QTCLASS ] tags and [ CODE ] tags...

Where did you set the translator? Do you make sure that every widget is making a retranslation after that?


But I still have a problem: only in one dialog it cannot translate, others are OK...

With some code we could eventually help. Without it is really hard!

FinderCheng
16th October 2009, 08:36
Hi,

there is a difference between [ QTCLASS ] tags and [ CODE ] tags...

Where did you set the translator? Do you make sure that every widget is making a retranslation after that?



With some code we could eventually help. Without it is really hard!

Sorry about the tags but I've no idea how to use it...

Well, here is my code:



// in main.cpp
int main(int argc, char *argv[])
{
QApplication app(argc, argv);

// i18n
QTranslator appTranslator;
appTranslator.load(":/pw"); // this is registered in a *.qrc file.
app.installTranslator(&appTranslator);
// Qt's translation
QTranslator qtTranslator;
qtTranslator.load(":/qt");
app.installTranslator(&qtTranslator);

app::MainWindow win;
win.showMaximized();

return app.exec();
}


And then in an action slot:



// in mainwindow.cpp
/* [private slot]
* Shows the about dialog.
*/
void app::MainWindow::showAboutDialog()
{
AboutDialog *ad = new AboutDialog();
ad->exec();
}


and in AboutDialog:



// in aboutdialog.cpp
app::AboutDialog::AboutDialog(QWidget *parent)
: QDialog(parent)
{
setWindowFlags(Qt::FramelessWindowHint);
setWindowTitle(tr("About PicWorks"));
}

Lykurg
16th October 2009, 08:47
Well if you can obviously set the [ QTCLASS ] then try to move your mouse a little bit more left to hit the # then you also can set the [ CODE ] tags!

Make the dialog a children of your mainwindow, then the translation should work.

FinderCheng
16th October 2009, 09:15
Well if you can obviously set the [ QTCLASS ] then try to move your mouse a little bit more left to hit the # then you also can set the [ CODE ] tags!

Make the dialog a children of your mainwindow, then the translation should work.

Thank you! I have edited my post already.

"a children"? Do you mean:



void app::MainWindow::showAboutDialog()
{
AboutDialog *ad = new AboutDialog(this);
ad->exec();
}

? If so, I tried this but it still doesn't work. On the other hand, I have almost the same code:


// in mainwindow.cpp
void PicWorks::MainWindow::newProWin()
{
ProjectCreateDialog *pcd = new ProjectCreateDialog;
pcd->exec();
}

This code works well!