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
Forum Updated to NodeBB v4.3 + New Features

How to load translation for static library widget

Scheduled Pinned Locked Moved Solved General and Desktop
qtranslatorstatic library
32 Posts 5 Posters 14.5k Views 4 Watching
  • 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, 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