Problem about Dynamic Language Translation
-
I want to implement Dynamic Language Translation in my application ,I implement the UI without qt Designer ,so I overload the changeEvent(QEvent *event) function ,but I can't switch the language ,what 's wrong with me .
Here is my code structure :@
CGameStartMenu::CGameStartMenu(QWidget *parent) :
QWidget(parent)
{
NewButton = new QPushButton(tr("New Game"));
OptionButton = new QPushButton(tr("Language"));translator=new QTranslator(this);
translator->load ("zh.qm");retranslate (); changeLanguage ();
}
void CGameStartMenu::changeEvent (QEvent *event)
{
if(event->type ()==QEvent::LanguageChange)
{
retranslate ();
}
QWidget::changeEvent (event);}
void CGameStartMenu::retranslate ()
{
NewButton->setText (tr("New Game"));
OptionButton->setText (tr("Language"));}
void CGameStartMenu::changeLanguage ()
{
// translator=new QTranslator(this);
// translator->load ("zh");
qApp->installTranslator (translator);
}
@Thank you !
My regards! -
This "FAQ":http://developer.qt.nokia.com/faq/answer/how_can_i_dynamically_switch_between_languages_in_my_application_using_e.g_ contains a complete example that illustrates how you can implement dynamic translation. You can follow the setup from that example to see if that helps getting the translation to work.