Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to load translation for static library widget

How to load translation for static library widget

Scheduled Pinned Locked Moved Solved General and Desktop
qtranslatorstatic library
32 Posts 5 Posters 14.3k 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.
  • K kshegunov
    10 Jan 2016, 11:10

    Hello,
    Something is amiss here, let's take it from the top. You said that you get the "Failed to load a translation for QT in your local language" message, but this message is to be shown when this fails:

        myTranslator->load(*local, QLatin1String("tester"), QLatin1String("_"), QLatin1String(":/i18n"))
    

    This particular line is in your application and tries to load an application translation, where does a static library resource come in play here? Could you tell what is the current language you're using and its iso code (you could use QLocale::language() and QLocale::languageToString), and make sure there's a matching translation file?

    Kind regards.

    M Offline
    M Offline
    mbnoimi
    wrote on 10 Jan 2016, 11:26 last edited by
    #16

    @kshegunov said:

    Hello,
    Something is amiss here, let's take it from the top. You said that you get the "Failed to load a translation for QT in your local language" message, but this message is to be shown when this fails: myTranslator->load(*local, QLatin1String("tester"), QLatin1String("_"), QLatin1String(":/i18n"))

    I didn't say that!
    I said I get Failed to load translation from static library which points to myTranslator->load(":/languages/arabic") failure!

    where does a static library resource come in play here?

    As I mentioned above this line suppose to load translation from static library's resource

    Could you tell what is the current language you're using and its iso code

    English; en_US

    K 1 Reply Last reply 10 Jan 2016, 11:49
    0
    • M mbnoimi
      10 Jan 2016, 11:26

      @kshegunov said:

      Hello,
      Something is amiss here, let's take it from the top. You said that you get the "Failed to load a translation for QT in your local language" message, but this message is to be shown when this fails: myTranslator->load(*local, QLatin1String("tester"), QLatin1String("_"), QLatin1String(":/i18n"))

      I didn't say that!
      I said I get Failed to load translation from static library which points to myTranslator->load(":/languages/arabic") failure!

      where does a static library resource come in play here?

      As I mentioned above this line suppose to load translation from static library's resource

      Could you tell what is the current language you're using and its iso code

      English; en_US

      K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 10 Jan 2016, 11:49 last edited by
      #17

      @mbnoimi

      I didn't say that!
      I said I get Failed to load translation from static library

      Indeed you did, it's my mistake, sorry.

      which points to myTranslator->load(":/languages/arabic") failure!

      Could you verify that this file is available? For example what does QFile::exists(":/languages/arabic") return, true or false? If the file exists then the problem is with the actual loading, if the file is not found, then I guess there's a problem with the resource initialization.

      Kind regards.

      Read and abide by the Qt Code of Conduct

      M 1 Reply Last reply 10 Jan 2016, 11:57
      0
      • K kshegunov
        10 Jan 2016, 11:49

        @mbnoimi

        I didn't say that!
        I said I get Failed to load translation from static library

        Indeed you did, it's my mistake, sorry.

        which points to myTranslator->load(":/languages/arabic") failure!

        Could you verify that this file is available? For example what does QFile::exists(":/languages/arabic") return, true or false? If the file exists then the problem is with the actual loading, if the file is not found, then I guess there's a problem with the resource initialization.

        Kind regards.

        M Offline
        M Offline
        mbnoimi
        wrote on 10 Jan 2016, 11:57 last edited by
        #18

        @kshegunov said:

        Could you verify that this file is available? For example what does QFile::exists(":/languages/arabic") return, true or false?

        I get true

        If the file exists then the problem is with the actual loading, if the file is not found, then I guess there's a problem with the resource initialization.

        After reviewing the project I discovered there are two "resources.qrc" the first one in the static library and the other in tester app. so I supposed this maybe makes Qt confused so I renamed one of them to a different name but unfortunately I still get same result.

        K 1 Reply Last reply 10 Jan 2016, 12:19
        0
        • M mrjj
          9 Jan 2016, 11:38

          Hi
          Maybe try

          QDirIterator it(":", QDirIterator::Subdirectories);
              while (it.hasNext()) {
                  qDebug() << it.next();
              }
          

          to have a look how the files are named in the running exe to to verify
          that they are indeed under ":/i18n" and paths are as you expect.

          M Offline
          M Offline
          mbnoimi
          wrote on 10 Jan 2016, 12:17 last edited by mbnoimi 1 Oct 2016, 12:18
          #19

          @mrjj said:

          QDirIterator it(":", QDirIterator::Subdirectories);
              while (it.hasNext()) {
                  qDebug() << it.next();
              }
          

          to have a look how the files are named in the running exe to to verify
          that they are indeed under ":/i18n" and paths are as you expect.

          I got this output:

          Failed to load translation from static library
          ":/qt-project.org"
          ":/qt-project.org/qmime"
          ":/qt-project.org/qmime/freedesktop.org.xml"
          ":/qt-project.org/styles"
          ":/qt-project.org/styles/commonstyle"
          ":/qt-project.org/styles/commonstyle/images"
          ":/qt-project.org/styles/commonstyle/images/networkdrive-16.png"
          ":/qt-project.org/styles/commonstyle/images/networkdrive-32.png"
          ":/qt-project.org/styles/commonstyle/images/dvd-16.png"
          ":/qt-project.org/styles/commonstyle/images/cdr-16.png"
          ":/qt-project.org/styles/commonstyle/images/up-16.png"
          ":/qt-project.org/styles/commonstyle/images/up-32.png"
          ":/qt-project.org/styles/commonstyle/images/dvd-32.png"
          ":/qt-project.org/styles/commonstyle/images/cdr-32.png"
          ":/qt-project.org/styles/commonstyle/images/left-32.png"
          ":/qt-project.org/styles/commonstyle/images/stop-32.png"
          ":/qt-project.org/styles/commonstyle/images/file-16.png"
          ":/qt-project.org/styles/commonstyle/images/down-16.png"
          ":/qt-project.org/styles/commonstyle/images/stop-24.png"
          ":/qt-project.org/styles/commonstyle/images/left-16.png"
          ":/qt-project.org/styles/commonstyle/images/down-32.png"
          ":/qt-project.org/styles/commonstyle/images/file-32.png"
          ":/qt-project.org/styles/commonstyle/images/dirlink-32.png"
          ":/qt-project.org/styles/commonstyle/images/diropen-32.png"
          ":/qt-project.org/styles/commonstyle/images/diropen-16.png"
          ":/qt-project.org/styles/commonstyle/images/cleartext-16.png"
          ":/qt-project.org/styles/commonstyle/images/dirlink-16.png"
          ":/qt-project.org/styles/commonstyle/images/networkdrive-128.png"
          ":/qt-project.org/styles/commonstyle/images/media-volume-muted-16.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-cancel-128.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-open-128.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-apply-32.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-apply-16.png"
          ":/qt-project.org/styles/commonstyle/images/fonttruetype-16.png"
          ":/qt-project.org/styles/commonstyle/images/newdirectory-128.png"
          ":/qt-project.org/styles/commonstyle/images/filecontents-128.png"
          ":/qt-project.org/styles/commonstyle/images/floppy-128.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-delete-16.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-delete-32.png"
          ":/qt-project.org/styles/commonstyle/images/harddrive-128.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-clear-32.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-close-32.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-clear-16.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-close-16.png"
          ":/qt-project.org/styles/commonstyle/images/dirclosed-128.png"
          ":/qt-project.org/styles/commonstyle/images/trash-128.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-apply-128.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-yes-16.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-yes-32.png"
          ":/qt-project.org/styles/commonstyle/images/fontbitmap-16.png"
          ":/qt-project.org/styles/commonstyle/images/newdirectory-32.png"
          ":/qt-project.org/styles/commonstyle/images/dirclosed-32.png"
          ":/qt-project.org/styles/commonstyle/images/newdirectory-16.png"
          ":/qt-project.org/styles/commonstyle/images/dirclosed-16.png"
          ":/qt-project.org/styles/commonstyle/images/up-128.png"
          ":/qt-project.org/styles/commonstyle/images/media-pause-32.png"
          ":/qt-project.org/styles/commonstyle/images/media-pause-16.png"
          ":/qt-project.org/styles/commonstyle/images/cdr-128.png"
          ":/qt-project.org/styles/commonstyle/images/dvd-128.png"
          ":/qt-project.org/styles/commonstyle/images/media-volume-16.png"
          ":/qt-project.org/styles/commonstyle/images/harddrive-32.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-cancel-16.png"
          ":/qt-project.org/styles/commonstyle/images/harddrive-16.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-hover-16.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-cancel-32.png"
          ":/qt-project.org/styles/commonstyle/images/viewdetailed-128.png"
          ":/qt-project.org/styles/commonstyle/images/fusion_groupbox.png"
          ":/qt-project.org/styles/commonstyle/images/right-128.png"
          ":/qt-project.org/styles/commonstyle/images/fileinfo-16.png"
          ":/qt-project.org/styles/commonstyle/images/filelink-16.png"
          ":/qt-project.org/styles/commonstyle/images/filelink-32.png"
          ":/qt-project.org/styles/commonstyle/images/fileinfo-32.png"
          ":/qt-project.org/styles/commonstyle/images/dirlink-128.png"
          ":/qt-project.org/styles/commonstyle/images/media-seek-forward-16.png"
          ":/qt-project.org/styles/commonstyle/images/media-seek-forward-32.png"
          ":/qt-project.org/styles/commonstyle/images/diropen-128.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-help-128.png"
          ":/qt-project.org/styles/commonstyle/images/viewdetailed-16.png"
          ":/qt-project.org/styles/commonstyle/images/viewdetailed-32.png"
          ":/qt-project.org/styles/commonstyle/images/media-seek-backward-16.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-ok-128.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-no-128.png"
          ":/qt-project.org/styles/commonstyle/images/media-seek-backward-32.png"
          ":/qt-project.org/styles/commonstyle/images/refresh-32.png"
          ":/qt-project.org/styles/commonstyle/images/refresh-24.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-save-128.png"
          ":/qt-project.org/styles/commonstyle/images/viewlist-128.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-yes-128.png"
          ":/qt-project.org/styles/commonstyle/images/computer-32.png"
          ":/qt-project.org/styles/commonstyle/images/computer-16.png"
          ":/qt-project.org/styles/commonstyle/images/parentdir-32.png"
          ":/qt-project.org/styles/commonstyle/images/parentdir-16.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-16.png"
          ":/qt-project.org/styles/commonstyle/images/media-play-16.png"
          ":/qt-project.org/styles/commonstyle/images/desktop-16.png"
          ":/qt-project.org/styles/commonstyle/images/media-stop-16.png"
          ":/qt-project.org/styles/commonstyle/images/desktop-32.png"
          ":/qt-project.org/styles/commonstyle/images/media-play-32.png"
          ":/qt-project.org/styles/commonstyle/images/down-128.png"
          ":/qt-project.org/styles/commonstyle/images/media-stop-32.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-delete-128.png"
          ":/qt-project.org/styles/commonstyle/images/media-skip-backward-32.png"
          ":/qt-project.org/styles/commonstyle/images/media-skip-backward-16.png"
          ":/qt-project.org/styles/commonstyle/images/fusion_arrow.png"
          ":/qt-project.org/styles/commonstyle/images/viewlist-16.png"
          ":/qt-project.org/styles/commonstyle/images/viewlist-32.png"
          ":/qt-project.org/styles/commonstyle/images/file-128.png"
          ":/qt-project.org/styles/commonstyle/images/floppy-32.png"
          ":/qt-project.org/styles/commonstyle/images/left-128.png"
          ":/qt-project.org/styles/commonstyle/images/floppy-16.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-no-32.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-ok-32.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-no-16.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-ok-16.png"
          ":/qt-project.org/styles/commonstyle/images/media-skip-forward-32.png"
          ":/qt-project.org/styles/commonstyle/images/media-skip-forward-16.png"
          ":/qt-project.org/styles/commonstyle/images/filelink-128.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-open-16.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-open-32.png"
          ":/qt-project.org/styles/commonstyle/images/fileinfo-128.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-help-32.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-help-16.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-save-16.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-save-32.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-down-16.png"
          ":/qt-project.org/styles/commonstyle/images/parentdir-128.png"
          ":/qt-project.org/styles/commonstyle/images/filecontents-32.png"
          ":/qt-project.org/styles/commonstyle/images/trash-32.png"
          ":/qt-project.org/styles/commonstyle/images/filecontents-16.png"
          ":/qt-project.org/styles/commonstyle/images/trash-16.png"
          ":/qt-project.org/styles/commonstyle/images/right-16.png"
          ":/qt-project.org/styles/commonstyle/images/right-32.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-clear-128.png"
          ":/qt-project.org/styles/commonstyle/images/standardbutton-close-128.png"
          ":/qt-project.org/styles/macstyle"
          ":/qt-project.org/styles/macstyle/images"
          ":/qt-project.org/styles/macstyle/images/toolbar-ext.png"
          ":/qt-project.org/styles/macstyle/images/dockdock-down-16.png"
          ":/qt-project.org/styles/macstyle/images/closedock-16.png"
          ":/qt-project.org/styles/macstyle/images/dockdock-16.png"
          ":/qt-project.org/styles/macstyle/images/closedock-down-16.png"
          ":/qt-project.org/styles/macstyle/images/toolbar-ext@2x.png"
          ":/qt-project.org/qmessagebox"
          ":/qt-project.org/qmessagebox/images"
          ":/qt-project.org/qmessagebox/images/qtlogo-64.png"
          ":/i18n"
          ":/i18n/tester_ar.qm"
          ":/i18n/tester_de.qm"
          ":/i18n/tester_fr.qm"
          ":/i18n/tester_en.qm"
          ":/i18n/tester_ru.qm"
          ":/i18n/tester_it.qm"
          ":/languages"
          ":/languages/i18n"
          ":/languages/i18n/WidgetKeyboard_fr.qm"
          ":/languages/i18n/WidgetKeyboard_ar.qm"
          ":/languages/i18n/WidgetKeyboard_de.qm"
          ":/languages/i18n/WidgetKeyboard_en.qm"
          ":/languages/i18n/WidgetKeyboard_it.qm"
          ":/languages/i18n/WidgetKeyboard_ru.qm"
          ":/images"
          ":/images/cut"
          ":/images/copy"
          ":/images/logo"
          ":/images/paste"
          ":/images/normalEcho"
          ":/images/passwdEcho"
          ":/sounds"
          ":/sounds/click.wav"
          QSoundEffect(pulseaudio): Error decoding source
          
          1 Reply Last reply
          0
          • M mbnoimi
            10 Jan 2016, 11:57

            @kshegunov said:

            Could you verify that this file is available? For example what does QFile::exists(":/languages/arabic") return, true or false?

            I get true

            If the file exists then the problem is with the actual loading, if the file is not found, then I guess there's a problem with the resource initialization.

            After reviewing the project I discovered there are two "resources.qrc" the first one in the static library and the other in tester app. so I supposed this maybe makes Qt confused so I renamed one of them to a different name but unfortunately I still get same result.

            K Offline
            K Offline
            kshegunov
            Moderators
            wrote on 10 Jan 2016, 12:19 last edited by
            #20

            @mbnoimi
            What about loading like this:

                translator->load("arabic", ":/languages");
            

            And as a second suggestion: I think you should create another QTranslator object for the second translation file.

            Kind regards.

            Read and abide by the Qt Code of Conduct

            M 1 Reply Last reply 10 Jan 2016, 12:24
            0
            • K kshegunov
              10 Jan 2016, 12:19

              @mbnoimi
              What about loading like this:

                  translator->load("arabic", ":/languages");
              

              And as a second suggestion: I think you should create another QTranslator object for the second translation file.

              Kind regards.

              M Offline
              M Offline
              mbnoimi
              wrote on 10 Jan 2016, 12:24 last edited by mbnoimi 1 Oct 2016, 12:24
              #21

              @kshegunov said:

              And as a second suggestion: I think you should create another QTranslator object for the second translation file.

              Thanks. This fixed Tester app. problem but it didn't fix the main problem (loading translation from static library) I still get this error message:

              Failed to load translation from static library

              K 1 Reply Last reply 10 Jan 2016, 12:27
              0
              • M mbnoimi
                10 Jan 2016, 12:24

                @kshegunov said:

                And as a second suggestion: I think you should create another QTranslator object for the second translation file.

                Thanks. This fixed Tester app. problem but it didn't fix the main problem (loading translation from static library) I still get this error message:

                Failed to load translation from static library

                K Offline
                K Offline
                kshegunov
                Moderators
                wrote on 10 Jan 2016, 12:27 last edited by
                #22

                @mbnoimi
                And have you tried the loading like this translator->load("arabic", ":/languages");, since you didn't comment on that?

                Read and abide by the Qt Code of Conduct

                M 2 Replies Last reply 10 Jan 2016, 12:29
                0
                • K kshegunov
                  10 Jan 2016, 12:27

                  @mbnoimi
                  And have you tried the loading like this translator->load("arabic", ":/languages");, since you didn't comment on that?

                  M Offline
                  M Offline
                  mbnoimi
                  wrote on 10 Jan 2016, 12:29 last edited by
                  #23

                  @kshegunov said:

                  @mbnoimi
                  And have you tried the loading like this translator->load("arabic", ":/languages");, since you didn't comment on that?

                  Didn't work :( I get same error message

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 10 Jan 2016, 12:35 last edited by
                    #24

                    Can I ask some silly maybe ?
                    The list shows
                    :/i18n/tester_ar.qm

                    There is no "arabic" under languages
                    there is
                    ":/languages/i18n/WidgetKeyboard_ar.qm"

                    1 Reply Last reply
                    0
                    • K kshegunov
                      10 Jan 2016, 12:27

                      @mbnoimi
                      And have you tried the loading like this translator->load("arabic", ":/languages");, since you didn't comment on that?

                      M Offline
                      M Offline
                      mbnoimi
                      wrote on 10 Jan 2016, 12:38 last edited by mbnoimi 1 Oct 2016, 12:39
                      #25

                      @kshegunov said:

                      And have you tried the loading like this translator->load("arabic", ":/languages");, since you didn't comment on that?

                      I tried to use translator->load(":/languages/i18n/WidgetKeyboard_ar") instead. The error message disappeared ("Failed to load translation from static library") but the widget comes from the static library still appears in English!

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 10 Jan 2016, 12:46 last edited by
                        #26

                        Silly question number 2.
                        The test calls ui->retranslateUi(this);
                        void Tester::changeEvent(QEvent *event)
                        {
                        if (event->type() == QEvent::LanguageChange) {
                        ui->retranslateUi(this);
                        } else
                        QWidget::changeEvent(event);
                        }
                        But tester ui->retranslate() knows about the widgets from the library ?
                        retranslateUi() just call all ->setText for elements inserted on the UI.
                        How can it know about widgets in the Lib?
                        Who calls widget_in_lib->setText?

                        M 1 Reply Last reply 10 Jan 2016, 13:02
                        0
                        • M mrjj
                          10 Jan 2016, 12:46

                          Silly question number 2.
                          The test calls ui->retranslateUi(this);
                          void Tester::changeEvent(QEvent *event)
                          {
                          if (event->type() == QEvent::LanguageChange) {
                          ui->retranslateUi(this);
                          } else
                          QWidget::changeEvent(event);
                          }
                          But tester ui->retranslate() knows about the widgets from the library ?
                          retranslateUi() just call all ->setText for elements inserted on the UI.
                          How can it know about widgets in the Lib?
                          Who calls widget_in_lib->setText?

                          M Offline
                          M Offline
                          mbnoimi
                          wrote on 10 Jan 2016, 13:02 last edited by
                          #27

                          @mrjj said:

                          But tester ui->retranslate() knows about the widgets from the library ?
                          retranslateUi() just call all ->setText for elements inserted on the UI.
                          How can it know about widgets in the Lib?
                          Who calls widget_in_lib->setText?

                          Fair point. But as you can see from the code the widget in static library built manually not by using Qt Designer so retranslate doesn't exist and I don't know how to create an alternative to it :(

                          M 1 Reply Last reply 10 Jan 2016, 13:11
                          0
                          • M mbnoimi
                            10 Jan 2016, 13:02

                            @mrjj said:

                            But tester ui->retranslate() knows about the widgets from the library ?
                            retranslateUi() just call all ->setText for elements inserted on the UI.
                            How can it know about widgets in the Lib?
                            Who calls widget_in_lib->setText?

                            Fair point. But as you can see from the code the widget in static library built manually not by using Qt Designer so retranslate doesn't exist and I don't know how to create an alternative to it :(

                            M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 10 Jan 2016, 13:11 last edited by mrjj 1 Oct 2016, 13:17
                            #28

                            @mbnoimi
                            well for dynamic translation, meaning load translation AFTER keyboard been created would be to call
                            void WidgetKeyBoard::createKeyboard(void) again.
                            As it seems to be the only place with tr(text);
                            retranslateUi() is very simple in all programs. it simply just sets the texts again
                            and the tr function gets the new text from the active translation.
                            Alternatively you need enum all widgets (in keyboard), get the text and re-set it via tr / directly look up trans text.
                            But it can be messy if many types of Widgets as then u need to handle the "setText" for each.

                            M 1 Reply Last reply 10 Jan 2016, 13:49
                            0
                            • M mrjj
                              10 Jan 2016, 13:11

                              @mbnoimi
                              well for dynamic translation, meaning load translation AFTER keyboard been created would be to call
                              void WidgetKeyBoard::createKeyboard(void) again.
                              As it seems to be the only place with tr(text);
                              retranslateUi() is very simple in all programs. it simply just sets the texts again
                              and the tr function gets the new text from the active translation.
                              Alternatively you need enum all widgets (in keyboard), get the text and re-set it via tr / directly look up trans text.
                              But it can be messy if many types of Widgets as then u need to handle the "setText" for each.

                              M Offline
                              M Offline
                              mbnoimi
                              wrote on 10 Jan 2016, 13:49 last edited by
                              #29

                              @mrjj said:

                              @mbnoimi
                              well for dynamic translation, meaning load translation AFTER keyboard been created would be to call
                              void WidgetKeyBoard::createKeyboard(void) again.

                              I tried to call createKeyboard() once again as following but still gives same result although this function calls tr() so it suppose to do what you talked about!

                              void Tester::changeEvent(QEvent *event)
                              {
                                  if (event->type() == QEvent::LanguageChange) {
                                      ui->retranslateUi(this);
                                      myKeyboard->createKeyboard();
                                  } else
                                      QWidget::changeEvent(event);
                              }
                              
                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on 10 Jan 2016, 14:16 last edited by mrjj 1 Oct 2016, 14:51
                                #30

                                Hi
                                Maybe you can
                                delete myKeyboard;
                                myKeyboard = new Keyboard(this);
                                as im not sure if calling createKeyboard() for same instance is 100% ok. (did not try it)

                                Then there is the context thing.
                                for mainwindow, its "mainwindow" (doh), but I do wonder about the translation that comes from static.

                                Since they are linked into "main", I assume its context is the same as main (tester) but if the
                                qm is different, it will not work.

                                So open them (qms) in Linguist and check the context they were extracted as.

                                then try with
                                http://doc.qt.io/qt-5/qcoreapplication.html#translate

                                To test a translation with that context and see if it does resolve.

                                First then I would worry about tr working in createKeyboard()

                                If I may say so.

                                update:
                                Context is "WidgetKeyBoard"
                                So calling createKeyboard() should be in the right context as we are in that class.

                                So testing with qcoreapplication.html#translate
                                to see if all is loaded and happy.

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  mbnoimi
                                  wrote on 19 Jan 2016, 13:08 last edited by
                                  #31

                                  Thank you guys, I'm no longer work on this project since Digia announcement.

                                  M 1 Reply Last reply 19 Jan 2016, 13:14
                                  0
                                  • M mbnoimi
                                    19 Jan 2016, 13:08

                                    Thank you guys, I'm no longer work on this project since Digia announcement.

                                    M Offline
                                    M Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on 19 Jan 2016, 13:14 last edited by
                                    #32

                                    @mbnoimi
                                    Ok, why if I can ask?

                                    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