Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Dialog standardButtons localization
Qt 6.11 is out! See what's new in the release blog

Dialog standardButtons localization

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 896 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CattivikC Offline
    CattivikC Offline
    Cattivik
    wrote on last edited by
    #1

    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 install qtbase_xx.qm translator 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

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bandler
      wrote on last edited by Bandler
      #2

      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();
          }
      
      1 Reply Last reply
      0
      • CattivikC Offline
        CattivikC Offline
        Cattivik
        wrote on last edited by
        #3

        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 MessageDialog component doesn't support dynamic translation, maybe.

        Hope this helps.
        -C

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved