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. [solved]How to embed qm translation files into executable

[solved]How to embed qm translation files into executable

Scheduled Pinned Locked Moved General and Desktop
qtranslatorembedresources
3 Posts 2 Posters 4.5k 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.
  • P Offline
    P Offline
    panch
    wrote on 19 Aug 2015, 10:03 last edited by panch
    #1

    Hi all,

    I have a Qt widget that I have made a translation file to. It works when loading using qm file path, but I would like to embed the qm file in the executable, and thus into the resources. So I made a qrc file that includes the qm file and also added

    TRANSLATIONS = myApp_da_DK.ts

    in the pro file. I then hoped that it would be a straight-forward thing to call the resource item like when you use icons or qml widgets. These are the tests:

    res = appTranslator.load("myApp_da_DK.qm");                                          // OK
    res = appTranslator.load("myApp_da_DK.qm", "qrc:/res/translations");                 // FAILS
    res = appTranslator.load("myApp_da_DK.qm", ":/res/translations");                    // FAILS
    if (res)
        app.installTranslator(&appTranslator);
    

    (filename of qm file hardcoded to make sure I din't get the name wrong)

    Do I have to do anything extraordinary to make it work?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      panch
      wrote on 19 Aug 2015, 10:42 last edited by
      #2

      Ok, so a quick update. There is no extra things needed to be done in order to make this work. I'm not sure if I accidentially mixed something up, but it actually works now. I think the reason for the loading not to work was the fact that I put the qm file in another resource file, which was prefixed inside the qrc file with "translations". I wasn't aware that I needed put this into the path of the load function.
      The way I discovered this was that the resources can be inspected through a QDir(":/") - this helped a lot in order to get the right search path!

      So in the end, I put the translation file next to the other resources in my resources.qrc file and indexed it like this:
      bool res = appTranslator.load("myApp_" + QLocale::system().name(), ":/res/translations");

      The qm file is thus located in the /res/translations subdir of the project root.

      Hopefully other people can benefit from this problem I had.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 19 Aug 2015, 20:27 last edited by
        #3

        Hi and welcome to devnet,

        Glad you found out and thanks for sharing !

        Since you have it working now, please update the thread title prepending [solved] so other forum users may know that a solution has been found :)

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        2/3

        19 Aug 2015, 10:42

        • Login

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