Dialog standardButtons localization
-
Hi!
I'm using Qt 6.8 to develop a QtQuick application running on Win11 x64. I'm on QtCreator 17.I would like to use dynamic translation for my app. I have some *.qm files deployed to a directory, and I can install
QTranslators on the fly.
That part works fine.The issues is related to QML Dialog
standardButtons: I can installqtbase_xx.qmtranslator but it seams to work only the first time!
Removing old translator and installing a new one doesn't work for me.It seams that Dialog standardButtons texts are "cached" in some way, and calling
engine.retranslate()has no effect on them.I know, I would provide translations for them, or use custom button footer on dialogs, and so on.... But I'm trying to figure out if I missed something.
Any suggestion?Thanks in advance
-C -
We load the control translations like this on language changes:
QTranslator qtTranslator; if (qtTranslator.load(QLocale(language), "qtquickcontrols", "_", QLibraryInfo::path(QLibraryInfo::TranslationsPath))) { QCoreApplication::installTranslator(&qtTranslator); engine->retranslate(); } -
Thanks @Bandler for your reply.
I started a test application from this example: https://doc.qt.io/qt-6/qtlinguist-localizedclock-example.html.
I'm doing the same to load myApp_xx.qm and then the other translator: I think that button texts are translated in qtbase_xx.qm file (qtquickcontrols was changed into qtdeclarative according to this, but it does not contain what I need).In my application I have a button to open a standard message dialog like this:
MessageDialog { title: qsTr("This is a standard message dialog") text: qsTr("The document has been modified.") informativeText: qsTr("Do you want to save your changes?") buttons: MessageDialog.Yes | MessageDialog.No }and a dropdown to change language and locale dynamically.
Something strange happens in two cases.
Case #1
- run application (default language is english)
- open the message (button texts are Yes and No)
- every attempt to change language fails for message buttons: all other application texts are correctly translated but message button texts remain in english.
Case #2
- run application (english default)
- change language to japanese (for example)
- open the message, and yes, now button text are in japanese!
- BUT every attempt to change language again fails from now on: message button texts still remain in japanese while all other texts in the app are correctly translated.
For that reason I can imagine that
MessageDialogcomponent doesn't support dynamic translation, maybe.Hope this helps.
-C