[Interest] Dynamic translation using Qt Quick 2.x in Qt5.1.1

Ramakanthreddy Kesireddy Ramakanthreddy.Kesireddy at techmahindra.com
Tue Oct 1 11:36:26 CEST 2013


Thanks for your mail.

When the language changes, have the LocaleUpdater emit the
localeChanged() signal. Does it mean we need to implement the event() function in LocaleUpdater
to catch the QEvent::Localechange event and emit localeChanged() signal?

Best Regards,

-----Original Message-----
From: interest-bounces+ramakanthreddy_kesireddy=mahindrasatyam.com at qt-project.org [mailto:interest-bounces+ramakanthreddy_kesireddy=mahindrasatyam.com at qt-project.org] On Behalf Of Bo Thorsen
Sent: 01 October 2013 13:19
To: interest at qt-project.org
Subject: Re: [Interest] Dynamic translation using Qt Quick 2.x in Qt5.1.1

Den 01-10-2013 07:36, Ramakanthreddy Kesireddy skrev:
> Hi,
> I would like to know if it is possible to update the text dynamically
> for any locale change in QtQuick(QML) using Qt5.1.1.

No, not directly. But there are a couple of things you can do instead.

The key in both my solutions is to have a single C++ object with a property registered to QML:

   class LocaleUpdater : public QObject {
     Q_PROPERTY(QString localeChange READ localeChange
       NOTIFY localeChanged)
     QString localeChange() const { return QString(); }

Export this to the QML:

   LocaleUpdater updater;
   qml.rootContext()->setContextProperty("localeUpdater", &updater);

When the language changes, have the LocaleUpdater emit the
localeChanged() signal. You can now do one of two things:

1) Use the text updater string directly:

   someObject.text: qsTr("Foo") + localeUpdater.localeChange

2) Catch the emitted signal and set all strings

   Connections {
     target: localeUpdater
     onLocaleChange: {
       someObject.text = qsTr("Foo")

I hope this helps.


Bo Thorsen, European Qt Manager, ICS
Integrated Computer Solutions. Delivering World-Class Applications http://ics.com/services _______________________________________________
Interest mailing list
Interest at qt-project.org


This email (including any attachments) is intended for the sole use of the intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or distribution or forwarding of any or all of the contents in this message is STRICTLY PROHIBITED. If you are not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated.

More information about the Interest mailing list