Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QTranslator doesn't load .qm file

QTranslator doesn't load .qm file

Scheduled Pinned Locked Moved Solved Mobile and Embedded
qt 5.6androidiosi18n
11 Posts 2 Posters 12.8k 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 19 Apr 2016, 21:28 last edited by
    #2

    Hi,

    Do you want to use these files from Qt's resource system or from a hard drive ? Because currently the path your are using in your translator.load call is within the resources but the build-directory note makes me think of a local deployment.

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

    E 1 Reply Last reply 20 Apr 2016, 05:05
    0
    • S SGaist
      19 Apr 2016, 21:28

      Hi,

      Do you want to use these files from Qt's resource system or from a hard drive ? Because currently the path your are using in your translator.load call is within the resources but the build-directory note makes me think of a local deployment.

      E Offline
      E Offline
      ekkescorner
      Qt Champions 2016
      wrote on 20 Apr 2016, 05:05 last edited by ekkescorner
      #3

      @SGaist as I understood it right, using TRANSLATIONS_FILES in my .pro will make the .qm part of the resource system.
      inside my project dir there are the /translations/*.ts files
      build and run on Android or iOS then lrelease from my code above in .pro creates the .qm from .ts and if I take a look at the build dirs for android or ios I see the /translations/.qm files at the root of the build dir

      I didn't found any hint to do additional things to have the *.qm available from android or ios

      is there anything wrong ? this stuff is new to me - developing BlackBerry Cascades (Qt 4.8) apps all the translations stuff was handled by magic - I only had to define the languages.

      thx for any help

      BTW: this is the complete .pro:

      TEMPLATE = app
      
      QT += qml quick core
      CONFIG += c++11
      
      SOURCES += main.cpp
      lupdate_only {
          SOURCES +=  main.qml \
          common/*.qml \
          demo/*.qml
      }
      
      OTHER_FILES += main.qml \
          common/*.qml \
          demo/*.qml
      
      RESOURCES += qml.qrc
      
      # Additional import path used to resolve QML modules in Qt Creator's code model
      QML_IMPORT_PATH =
      
      # Default rules for deployment.
      include(deployment.pri)
      
      # var, prepend, append
       defineReplace(prependAll) {
           for(a,$$1):result += $$2$${a}$$3
           return($$result)
       }
      # Supported languages
      LANGUAGES = de en fr
      # Available translations
      TRANSLATIONS = $$PWD/translations/one_page_ui.ts
      TRANSLATIONS += $$prependAll(LANGUAGES, $$PWD/translations/one_page_ui_, .ts)
      
      # Used to embed the qm files in resources
      TRANSLATIONS_FILES =
      
      # run LRELEASE to generate the qm files
      qtPrepareTool(LRELEASE, lrelease)
       for(tsfile, TRANSLATIONS) {
           qmfile = $$shadowed($$tsfile)
           qmfile ~= s,\\.ts$,.qm,
           qmdir = $$dirname(qmfile)
           !exists($$qmdir) {
               mkpath($$qmdir)|error("Aborting.")
           }
           command = $$LRELEASE -removeidentical $$tsfile -qm  $$qmfile
           system($$command)|error("Failed to run: $$command")
           TRANSLATIONS_FILES += $$qmfile
       }
      
      

      ekke ... Qt Champion 2016 | 2024 ... mobile business apps
      5.15 --> 6.8 https://t1p.de/ekkeChecklist
      QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

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

        OK, I think I'm following you now.

        If I understood correctly, that technique doesn't use Qt's resource system but create the files as a "resource to use by your application" i.e. it generates the files besides your application in a folder named "translations" that your should be able to access easily but not using :/ as protocol. If you want to embedded them within your executable you have to create a .qrc file for them.

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

        E 3 Replies Last reply 20 Apr 2016, 07:04
        0
        • S SGaist
          20 Apr 2016, 06:53

          OK, I think I'm following you now.

          If I understood correctly, that technique doesn't use Qt's resource system but create the files as a "resource to use by your application" i.e. it generates the files besides your application in a folder named "translations" that your should be able to access easily but not using :/ as protocol. If you want to embedded them within your executable you have to create a .qrc file for them.

          E Offline
          E Offline
          ekkescorner
          Qt Champions 2016
          wrote on 20 Apr 2016, 07:04 last edited by
          #5

          @SGaist thx for the hint. will try this
          but then I need the .qm files in my project dir
          this generates them into the build dir

          # run LRELEASE to generate the qm files
          qtPrepareTool(LRELEASE, lrelease)
           for(tsfile, TRANSLATIONS) {
               qmfile = $shadowed($tsfile)
               qmfile ~= s,\\.ts$,.qm,
               qmdir = $dirname(qmfile)
               !exists($qmdir) {
                   mkpath($qmdir)|error("Aborting.")
               }
               command = $LRELEASE -removeidentical $tsfile -qm  $qmfile
               system($command)|error("Failed to run: $command")
               TRANSLATIONS_FILES += $qmfile
           }
          

          any idea how to change this to get the qm files from lrelease in my project dir /translations besides the .ts ?

          ekke ... Qt Champion 2016 | 2024 ... mobile business apps
          5.15 --> 6.8 https://t1p.de/ekkeChecklist
          QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

          1 Reply Last reply
          0
          • S SGaist
            20 Apr 2016, 06:53

            OK, I think I'm following you now.

            If I understood correctly, that technique doesn't use Qt's resource system but create the files as a "resource to use by your application" i.e. it generates the files besides your application in a folder named "translations" that your should be able to access easily but not using :/ as protocol. If you want to embedded them within your executable you have to create a .qrc file for them.

            E Offline
            E Offline
            ekkescorner
            Qt Champions 2016
            wrote on 20 Apr 2016, 07:20 last edited by
            #6

            @SGaist found it. will post later the solution. it works now using .qrc. thx

            ekke ... Qt Champion 2016 | 2024 ... mobile business apps
            5.15 --> 6.8 https://t1p.de/ekkeChecklist
            QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

            1 Reply Last reply
            0
            • S SGaist
              20 Apr 2016, 06:53

              OK, I think I'm following you now.

              If I understood correctly, that technique doesn't use Qt's resource system but create the files as a "resource to use by your application" i.e. it generates the files besides your application in a folder named "translations" that your should be able to access easily but not using :/ as protocol. If you want to embedded them within your executable you have to create a .qrc file for them.

              E Offline
              E Offline
              ekkescorner
              Qt Champions 2016
              wrote on 20 Apr 2016, 07:49 last edited by ekkescorner
              #7

              @SGaist this way it runs on Android and iOS as expected:

              TEMPLATE = app
              
              QT += qml quick core
              CONFIG += c++11
              
              SOURCES += main.cpp
              lupdate_only {
                  SOURCES +=  main.qml \
                  common/*.qml \
                  demo/*.qml
              }
              
              OTHER_FILES += main.qml \
                  common/*.qml \
                  demo/*.qml
              
              RESOURCES += qml.qrc \
                  translations.qrc
              
              # Additional import path used to resolve QML modules in Qt Creator's code model
              QML_IMPORT_PATH =
              
              # Default rules for deployment.
              include(deployment.pri)
              
              # T R A N S L A T I O N S
              
              # if languages are added:
              # 1. rebuild project to generate *.qm
              # 2. add existing .qm files to translations.qrc
              
              # if changes to translatable strings:
              # 1. Run Tools-External-Linguist-Update
              # 2. Run Linguist and do translations
              # 3. Build and run on iOS and Android to verify translations
              
              # Supported languages
              LANGUAGES = de en fr
              
              # used to create .ts files
               defineReplace(prependAll) {
                   for(a,$$1):result += $$2$${a}$$3
                   return($$result)
               }
              # Available translations
              TRANSLATIONS = $$PWD/translations/one_page_ui.ts
              TRANSLATIONS += $$prependAll(LANGUAGES, $$PWD/translations/one_page_ui_, .ts)
              # run LRELEASE to generate the qm files
              qtPrepareTool(LRELEASE, lrelease)
               for(tsfile, TRANSLATIONS) {
                   qmfile = $$tsfile
                   qmfile ~= s,\\.ts$,.qm,
                   command = $$LRELEASE -removeidentical $$tsfile -qm  $$qmfile
                   system($$command)|error("Failed to run: $$command")
               }
              

              thx for helping. now I understand it better how it works
              question: I'm using the app name (one_page_ui) sometimes inside .pro. Can I replace this using a variable ?

              BTW: is there a way to create a .qrc and add files dynamically from inside .pro ? would be great to eliminate this manual step.

              ekke ... Qt Champion 2016 | 2024 ... mobile business apps
              5.15 --> 6.8 https://t1p.de/ekkeChecklist
              QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 20 Apr 2016, 20:54 last edited by
                #8

                Usually you have the application name stored in the TARGET variable that you can then re-use.

                You can try to create your own custom target that you would run before the build starts.

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

                E 1 Reply Last reply 21 Apr 2016, 22:16
                0
                • S SGaist
                  20 Apr 2016, 20:54

                  Usually you have the application name stored in the TARGET variable that you can then re-use.

                  You can try to create your own custom target that you would run before the build starts.

                  E Offline
                  E Offline
                  ekkescorner
                  Qt Champions 2016
                  wrote on 21 Apr 2016, 22:16 last edited by ekkescorner
                  #9

                  @SGaist now I added TARGET and changed creation of .ts files and reduced required code for lrelease
                  here's my final way to deal with .ts / .qm:

                  TEMPLATE = app
                  TARGET = one_page_ui
                  
                  QT += qml quick core
                  CONFIG += c++11
                  
                  SOURCES += main.cpp
                  lupdate_only {
                      SOURCES +=  main.qml \
                      common/*.qml \
                      demo/*.qml
                  }
                  
                  OTHER_FILES += main.qml \
                      common/*.qml \
                      demo/*.qml
                  
                  RESOURCES += qml.qrc \
                      translations.qrc
                  
                  # Additional import path used to resolve QML modules in Qt Creator's code model
                  QML_IMPORT_PATH =
                  
                  # Default rules for deployment.
                  include(deployment.pri)
                  
                  # T R A N S L A T I O N S
                  
                  # if languages are added:
                  # 1. rebuild project to generate *.qm
                  # 2. add existing .qm files to translations.qrc
                  
                  # if changes to translatable strings:
                  # 1. Run Tools-External-Linguist-Update
                  # 2. Run Linguist and do translations
                  # 3. Build and run on iOS and Android to verify translations
                  
                  # Supported languages
                  LANGUAGES = de en fr
                  
                  # used to create .ts files
                   defineReplace(prependAll) {
                       for(a,$$1):result += $$2$${a}$$3
                       return($$result)
                   }
                  # Available translations
                  tsroot = $$join(TARGET,,,.ts)
                  tstarget = $$join(TARGET,,,_)
                  TRANSLATIONS = $$PWD/translations/$$tsroot
                  TRANSLATIONS += $$prependAll(LANGUAGES, $$PWD/translations/$$tstarget, .ts)
                  # run LRELEASE to generate the qm files
                  qtPrepareTool(LRELEASE, lrelease)
                   for(tsfile, TRANSLATIONS) {
                       command = $$LRELEASE $$tsfile
                       system($$command)|error("Failed to run: $$command")
                   }
                  

                  only manual step required is to run lupdate if translatable strings changed in src or qml

                  ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                  5.15 --> 6.8 https://t1p.de/ekkeChecklist
                  QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                  1 Reply Last reply
                  0
                  • E Offline
                    E Offline
                    ekkescorner
                    Qt Champions 2016
                    wrote on 2 May 2016, 06:56 last edited by
                    #10

                    FWIW: I have written a blog about this: http://j.mp/qt-i18n

                    ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                    5.15 --> 6.8 https://t1p.de/ekkeChecklist
                    QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 2 May 2016, 21:35 last edited by
                      #11

                      Thanks !

                      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