[Qt-interest] Query related to Internationalization in loading .qm file at runtime
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Mon Feb 2 09:56:55 CET 2009
Hemalatha Venkataswamy wrote on Friday, January 30, 2009 1:21 PM:
> ... . The language is not affected immediately to the
> widgets. I need to close my application and open the application to
> see the application loaded with a new language.
>
> Could anyone help me in answering, what I need to do to load the
> applciation with .qm file once I select the language from the
> combo-box.
Your widget gets an event: QEvent::LanguageChange (http://doc.trolltech.com/4.4/qevent.html#Type-enum). You catch this event through the http://doc.trolltech.com/4.4/qwidget.html#changeEvent method (which you override in your custom widgets).
Widgets/dialogs designed by Qt Designer do implement this automatically, so (in theory) you only need to worry about your custom widgets.
Once you receive this event you do something like this (pseudo-code):
MyWidget::MyWidget(QWidget *parent;)
{
...
// create the custom widgets
this->createWidgets(parent);
// set the text (to be translated)
this->updateText();
...
}
// a new *.qm file has been loaded
void MyWidget::changeEvent(QEvent ev)
{
...
if (ev instanceof Qt::QLanguageChangeEvent)
{
this->updateText();
}
...
}
// tr() will make sure that the text is properly translated,
// given the current *.qm file
void MyWidget::updateText()
{
label->setText(tr("Text to be translated");
this->setTitle(tr("Title to be translated");
...
}
There is a Qt example which shows how this works (at least I remember one from Qt 3 times), but I can't find it right now ;)
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list