Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. QT - Read translator file .ts/.qm on translations.qrc file
Forum Updated to NodeBB v4.3 + New Features

QT - Read translator file .ts/.qm on translations.qrc file

Scheduled Pinned Locked Moved Unsolved Language Bindings
6 Posts 3 Posters 4.1k 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.
  • L Offline
    L Offline
    lele86
    wrote on 10 Apr 2017, 15:22 last edited by
    #1

    Hi guys, I'm trying to import translator file on my qt project (QT 5.6 on linux system), but I can't upload translation file because "load" function of "QTranslator" returns always "false".

    I have the following project structure:

    Project root: /
    /resources/translations.qrc
    /resources/translations/app_it .qm and .ts
    /resources/translations/app_en .qm and .ts
    ...

    In main.cpp file of qt application I have the following source code:

    QTranslator *translator = new QTranslator();
    bool isFileTranslatorLoaded = translator->load(":/translations/translations/app_it);
    

    isFileTranslatorLoaded always returns false.

    File translations.qrc:

    <RCC>
        <qresource prefix="/translations">
            <file>translations/app_it.ts</file>
            <file>translations/app_it.qm</file>
            <file>translations/app_en.ts</file>
            <file>translations/app_en.qm</file>
        <qresource>
    <RCC>
    

    How can I solve this issue?

    Thanks in Advice

    Best Regards Daniele

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 10 Apr 2017, 21:59 last edited by
      #2

      Hi and welcome to devnet,

      You are passing an invalid path. You only need the processed version .qm there's no need for the *.ts files.

      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
      0
      • L Offline
        L Offline
        lele86
        wrote on 12 Apr 2017, 07:06 last edited by lele86 4 Dec 2017, 07:10
        #3

        I have followed your suggestions but isFileTranslatorLoaded returns always false. In c++ code I wrote bool "isFileTranslatorLoaded = translator->load(":/translations/appit.qm");" and my resource file is:

        <RCC>
        <qresource prefix="/translations" lang="it">
        <file alias="appit.qm">translations/app_it.qm</file>
        </qresource>
        <qresource prefix="/translations" lang="en">
        <file alias="appen.qm">translations/app_en.qm</file>
        </qresource>
        </RCC>

        I don't know why the .qm file isn't loaded. It seems that the resource file is not loaded in the main.cpp file.

        Thanks in advice.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 12 Apr 2017, 12:06 last edited by
          #4

          Because you are using lang="it" this means that the file is only available if your locale is Italian. See the resources chapter in Qt's documentation for a more thorough explanation.

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

          A 1 Reply Last reply 12 Aug 2017, 17:47
          0
          • S SGaist
            12 Apr 2017, 12:06

            Because you are using lang="it" this means that the file is only available if your locale is Italian. See the resources chapter in Qt's documentation for a more thorough explanation.

            A Offline
            A Offline
            ahmad88me
            wrote on 12 Aug 2017, 17:47 last edited by
            #5

            Hi @SGaist , This doesn't work for me as well. I tried with using lang=en, lang=ar and without the lang attribute.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 12 Aug 2017, 22:52 last edited by
              #6

              Hi,

              What exactly doesn't work ?

              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
              0

              • Login

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