Retranslate

Enables dynamic translation and locale updates in QML.

Adding properties from the Retranslate class to text properties in a QML component enables the text to be updated with translated strings when the system's locale or language is changed. The QML text properties will be notified to update via the property change signals container in this class.

Container {
    Label {
        text: qsTr("This text will be translated") + Retranslate.onLanguageChanged
    } 
}
// The following C++ code will trigger the Retranslate.onLanguageChanged signal and update the
// text within the qsTr() function with the translated string.
void MyClass::loadTranslator() {
    myTranslator.load("path/to/translator.qm"));
    QCoreApplication::instance()->installTranslator(myTranslator);
}


Overview

QML properties

onLanguageChanged: QString [read-only]
onLocaleChanged: QString [read-only]
onLocaleOrLanguageChanged: QString [read-only]

Properties Index

Properties

QString onLanguageChanged[read-only]

Notification property that enables text to be dynamically updated with localized strings when the system language is changed.

This property will always return an empty QString. When a language change occurs, a signal is emitted that informs the application that the text this property is attached is to update.

Container {
    Label { 
        text: qsTr("This will be translated") + Retranslate.onLanguageChanged
    } 
}

QString onLocaleChanged[read-only]

Notification property that enables text to be dynamically updated with localized strings when the system locale is changed.

This property will always return an empty QString. When a locale change occurs, a signal is emitted that informs the application that the text this property is attached is to update.

Container {
    Label {
        text: qsTr("This will be translated") + Retranslate.onLocaleChanged
    } 
}

QString onLocaleOrLanguageChanged[read-only]

Notification property that enables text to be dynamically updated with localized strings when the system locale or language is changed.

This property will always return an empty QString. When a locale or language change occurs, a signal is emitted that informs the application that the text this property is attached is to update.

Container {
    Label {
        text: qsTr("This will be translated") + Retranslate.onLocaleOrLanguageChanged
    } 
}

Public Functions

const QString onLanguageChanged ()

Returns an empty QString to avoid changing the translation key on which the property is added to.

Return:

An empty QString

const QString onLocaleChanged ()

Returns an empty QString to avoid changing the translation key on which the property is added to.

Return:

An empty QString

const QString onLocaleOrLanguageChanged ()

Returns an empty QString to avoid changing the translation key on which the property is added to.

Return:

An empty QString.

Signals

void onLanguageChangedChanged ()

Emitted when the system language is changed.

void onLocaleChangedChanged ()

Emitted when the system locale is changed.

void onLocaleOrLanguageChangedChanged ()

Emitted when the system language or locale is changed.

Last modified: 2014-09-29



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus