PDA

View Full Version : UI translation



Annihilator
23rd September 2010, 20:59
Hi to all!
I generate ui_mainwindow.h from form where is all interface. Also I create context menu for tray icon after setupUI():

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
ui(new Ui::MainWindow), m_signalsIsBlocked(false)
{
ui->setupUi(this);
//........................
//..........................
CreateActions();
//......................
}

void MainWindow::CreateActions()
{
minimizeAction = new QAction(QObject::tr("Mi&nimize"), this);
connect(minimizeAction, SIGNAL(triggered()), this, SLOT(on_actionMinimize_triggered()));

maximizeAction = new QAction(tr("Ma&ximize"), this);
connect(maximizeAction, SIGNAL(triggered()), this, SLOT(on_actionMaximize_triggered()));

restoreAction = new QAction(tr("&Restore"), this);
connect(restoreAction, SIGNAL(triggered()), this, SLOT(on_actionRestore_triggered()));

quitAction = new QAction(tr("&Quit"), this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
}
Then I make *.ts by using lupdate, after that translate strings and make *.qm by using lrelease.

Then I add code to main():


QApplication a(argc, argv);
QTranslator appTrans;
QString langFile(":/i18n/vdynclient_ru_RU.qm"); // Russian translation
appTrans.load(langFile);
a.installTranslator(&appTrans);

But I get translated strings only for tray context menu, but not for all interface.
I tried to check translation by:

QString transl = appTrans.translate("MainContext", "Your E-mail:");
And got correct translation, cause one exists, but why isn`t it displayed on the form (every time I see only english words)?
Can anybody help, please?

wladek
24th September 2010, 10:54
Hi Annihilator,

Can you please post a working example?
It would be easier to help you in this way.

Regards,
Wladek

Annihilator
28th September 2010, 12:37
Hi wladek. I resolved this issue. Just created another project and place all files in one folder. I placed file in separate folders (src, ui) before that. I think this was a problem.

Regards,
Ruslan