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. Localization of a library
Qt 6.11 is out! See what's new in the release blog

Localization of a library

Scheduled Pinned Locked Moved General and Desktop
30 Posts 4 Posters 22.6k Views 1 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.
  • R Offline
    R Offline
    realdarkman
    wrote on last edited by
    #21

    What is the path from MyApp to MyLip german.qm?

    @
    libTranslator.load(":/locale/german.qm")
    libTranslator.load(":/mylib/locale/german.qm")
    @

    ...both doesn't work!

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #22

      @
      int main(int argc, char *argv[])
      {
      QApplication application(argc, argv);

      QTranslator libTranslator;
      ...
      MyLib::loadTranslation(libTranslator);
      QApplication::installTranslator(&libTranslator);
      
      ...
      return application.exec();
      

      }

      void loadTranslation(QTranslator& translator)
      {
      translator.load("/home/chris/myLib/locale/german.qm");
      }
      @

      LoadTranslator must be exported from the dll.

      The path to use for the load depends on your resource file. we can't tell you.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • R Offline
        R Offline
        realdarkman
        wrote on last edited by
        #23

        Ok, I made it so, Gerolf! Unfortunately, same behavior: MyApp german, but MyLib english strings/forms!

        libTranslator.load(...) returns true ... I despair soon!

        1 Reply Last reply
        0
        • R Offline
          R Offline
          realdarkman
          wrote on last edited by
          #24

          With local file on hdd it works:

          @translator.load("/home/chris/mylib/locale/german.qm")@

          but if I use the resource, it doesn't work:

          @translator.load(":/locale/german.qm")@

          Both returns true! (?)

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #25

            Your library needs to incorporate the resource file of the library. In order to not clash with names in your application, it's a good idea to put those resources into a virtual directory in the resources, e.g

            @
            :/mylibrary/locale/german.qm
            @

            Also, it may be necessary to explicitly initialize the library's ressources with "Q_INIT_RESOURCE":/doc/qt-4.8/qdir.html#Q_INIT_RESOURCE. The "Qt Resource System docs":/doc/qt-4.8/resources.html have some infos on that topic too (look at the end of the page).

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • R Offline
              R Offline
              realdarkman
              wrote on last edited by
              #26

              It works now, thanks!

              @all:
              Big thanks for your help! You're great!

              Last thing: I load the Qt translations (qt_de.qm) in MyApp, must this be done also in MyLib for Qt strings (error messages etc.) in the library?

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #27

                You're welcome - that's what this forums are made for :-)
                Please make sure to add [solved] to the title of the topic (the edit link is at the very first post).

                Regarding your last question:
                No, it's only needed in the application itself.

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  realdarkman
                  wrote on last edited by
                  #28

                  Ok, but Qt error strings are english only, allthough qt_de.qm is loaded! This returns an english message (it's in the library):

                  @QIODevice::errorString()@

                  ...or are these strings english only?

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    giesbert
                    wrote on last edited by
                    #29

                    AFAIK, these translations are only for UI stuff like dialogs etc.
                    Not for error strings, which you typically do not directly display to the end user.

                    Nokia Certified Qt Specialist.
                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      realdarkman
                      wrote on last edited by
                      #30

                      Ok, but I found translations in qt_de.ts for error messages! I load qt_de.qm in MyApp, but my library doesn't use it! If I load qt_de.qm in MyLib, strings are still in english! Any special options to load it for libraries?

                      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