PDA

View Full Version : QTranslator: the menu is not translated



trallallero
26th October 2011, 07:46
I'm working on a GUI that uses QTranslator and everything works fine.
I load the language at start up and can change it on the fly.
The only problem is that the menu (menuBar) is not translated when the language is switched.
If I save the options and restart the GUI, then the menu is in the right language but if I
change the language on the fly, the menu is not translated.

I create the menu after having installed the translator.
I create all the menus/actions with the tr("name") function.

What am I missing ?
thanks

Added after 18 minutes:

Another question: is it possible to run lupdate automatically from the makefile ?
If yes, what should I write in the .pro file ?

d_stranz
27th October 2011, 17:21
Are you putting "shortcut" characters into the menu item strings? If so, it could be that the translator is not finding an exact match, so does not make a translation.

trallallero
28th October 2011, 06:50
Yes, of course I put shortcuts. Anyway, it's not nice but I've solved with an UpdateMenus() function, thanks.

wysota
28th October 2011, 07:20
Do you handle LanguageChange event for the widget that adds items to the menus?

trallallero
28th October 2011, 07:28
Yes, I do.


void MainWindow::changeEvent(QEvent* event)
{
if (event->type() == QEvent::LanguageChange)
{
ui->retranslateUi(this);
SetTablesFields();
UpdateMenus();

if (m_DBGui)
m_DBGui->Retranslate();
if (m_LogGui)
m_LogGui->Retranslate();
if (m_PluginOptionsGui)
m_PluginOptionsGui->Retranslate();
}
QMainWindow::changeEvent(event);
}
///////////////////////////////////////////////////////////////

wysota
28th October 2011, 08:01
That's the proper way of retranslating widgets.

trallallero
28th October 2011, 08:42
Good to know that it's done in a proper way, thanks... so at least I know it's not my fault :D

wysota
28th October 2011, 08:56
Just the name "UpdateMenus()" is a bit wrong here. Call it retranslateMenus() and also call it the first time you set items to the menu. Have a look at code generated by Designer, it has a similar method.