PDA

View Full Version : Problems about Dynamic Language Switching



to_guliang
9th March 2010, 02:35
hi to all!
I'd like to do dynamic language switching in my application,but there is a problem.

there are three language in my project:english, Chinese simplified and Chinese Traditional. I chagne the language by the menu.


connect(actE,SIGNAL(triggered()),this,SLOT(LanEnli sh()));


if(languageType == 0)
{
return;
}

translator.load("language_Eng");
qApp->installTranslator(&translator);
retranslateUi(this);

//call the retranslateUi() in the ComSetup and Navigation, the ComSetup and Navigation are dialogs designered by the QT designer
ComSetup->SwitchLanguage();
Navigation->SwitchLanguage();

languageType = 0;


Now the problem is like this: the language are designed in the QT designer in the dialog could be translated exactly. the language that added to the dialog in the program(.cpp)can't be translated. for example, there is "dockWidget = new QDockWidget(tr("Navigation"),this);" in the .cpp,the "Navigation" can't be translated. i make sure the according word has been translateed in the "language_Eng".


Do you know what I mean? Have you got any ideas what's wrong with it ?
Regards to all.

vladozar
10th March 2010, 15:38
I have a similar issue, what i have done, is it will translate all sub widgets (all widgets that are part of the program) but will not translate MainWindow. I use Qt SDK 2010.01 and all my ui is designed in QtCreators Designer.

here is my code that i use for switching between languages, SoftProjector is my MainWindow:

softprojector.h

private:
QTranslator translator;


softprojector.cpp

void SoftProjector::on_actionRussian_triggered()
{
translator.load(":sotftpro_ru");
QApplication::installTranslator(&translator);
}

void SoftProjector::on_actionEnglish_triggered()
{
QApplication::removeTranslator(&translator);
}

The code will translate everything but the MainWindow.

What changes do i need to make so that it would dynamically translate entire program (not in main.cpp)?

Thanks

vladozar
11th March 2010, 00:17
Now the problem is like this: the language are designed in the QT designer in the dialog could be translated exactly. the language that added to the dialog in the program(.cpp)can't be translated. for example, there is "dockWidget = new QDockWidget(tr("Navigation"),this);" in the .cpp,the "Navigation" can't be translated. i make sure the according word has been translateed in the "language_Eng".


Do you know what I mean? Have you got any ideas what's wrong with it ?
Regards to all.4397

In Designer make sure that translatable property of all text items have been check. see attachment image
I believe this is the same as using tr() in code.