Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Deploy QML app to devices with languages files
Forum Updated to NodeBB v4.3 + New Features

Deploy QML app to devices with languages files

Scheduled Pinned Locked Moved Solved QML and Qt Quick
17 Posts 5 Posters 2.0k Views 2 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.
  • S sharath

    Hi @DavidM29,

    You can follow this , It would help you to solve.

    D Offline
    D Offline
    DavidM29
    wrote on last edited by
    #5

    @sharath
    I do use the qm files for translation, and I have followed the post you gave.
    But on the target it is look for the qm file on the target but as I deploy them from Qt creator they are not deployed on the target. I'm looking for a way to deploy them as well. My translation is working nicely

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #6

      As said, use QRC. Your QM files will be compiled into the executable - they will always be there, without any need to search for them in directory tree.

      (Z(:^

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DavidM29
        wrote on last edited by
        #7

        Then I don't understand why it does not work. I do have the qrc file, the qm file and the translator cpp side. Everything works fine when I add manually the files.

        J.HilkJ sierdzioS 2 Replies Last reply
        0
        • D DavidM29

          Then I don't understand why it does not work. I do have the qrc file, the qm file and the translator cpp side. Everything works fine when I add manually the files.

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #8

          @DavidM29 please show us how you load the translation file


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DavidM29
            wrote on last edited by DavidM29
            #9

            Here is the .pro side :

            RESOURCES += qml.qrc \
                image.qrc \
                font.qrc \
            #this is the one with my qm files
                language.qrc  
            
            TRANSLATIONS = Langues/lang_en_US.ts \
                           Langues/lang_fr_FR.ts \
                           Langues/lang_de_DE.ts \
                           Langues/lang_da_DA.ts \
                           Langues/lang_es_ES.ts \
                           Langues/lang_pl_PL.ts \
                           Langues/lang_cz_CZ.ts
            
            lupdate_only{
             *.qml
            }
            

            The cpp side is the quite the same as the one in the link provided by sharath (the empty string as well because I use Qt 5.6.3 can't upgrade it)

            1 Reply Last reply
            0
            • D DavidM29

              Then I don't understand why it does not work. I do have the qrc file, the qm file and the translator cpp side. Everything works fine when I add manually the files.

              sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #10

              @DavidM29 said in Deploy QML app to devices with languages files:

              Then I don't understand why it does not work. I do have the qrc file, the qm file and the translator cpp side. Everything works fine when I add manually the files.

              You need to put QM files inside your QRC file. You have to do it yourself, Qt won't magically do it for you. Then you need to use proper QRC paths to load the translations (so `":/path/to/file.qm" instead of normal filesystem path).

              (Z(:^

              D 1 Reply Last reply
              1
              • sierdzioS sierdzio

                @DavidM29 said in Deploy QML app to devices with languages files:

                Then I don't understand why it does not work. I do have the qrc file, the qm file and the translator cpp side. Everything works fine when I add manually the files.

                You need to put QM files inside your QRC file. You have to do it yourself, Qt won't magically do it for you. Then you need to use proper QRC paths to load the translations (so `":/path/to/file.qm" instead of normal filesystem path).

                D Offline
                D Offline
                DavidM29
                wrote on last edited by
                #11

                @sierdzio
                I did here is my qrc file :

                <RCC>
                    <qresource prefix="/">
                        <file>Langues/lang_fr_FR.qm</file>
                        <file>Langues/lang_en_US.qm</file>
                        <file>Langues/lang_cz_CZ.qm</file>
                        <file>Langues/lang_da_DA.qm</file>
                        <file>Langues/lang_de_DE.qm</file>
                        <file>Langues/lang_es_ES.qm</file>
                        <file>Langues/lang_pl_PL.qm</file>
                    </qresource>
                </RCC>
                
                
                J.HilkJ sierdzioS 2 Replies Last reply
                0
                • D DavidM29

                  @sierdzio
                  I did here is my qrc file :

                  <RCC>
                      <qresource prefix="/">
                          <file>Langues/lang_fr_FR.qm</file>
                          <file>Langues/lang_en_US.qm</file>
                          <file>Langues/lang_cz_CZ.qm</file>
                          <file>Langues/lang_da_DA.qm</file>
                          <file>Langues/lang_de_DE.qm</file>
                          <file>Langues/lang_es_ES.qm</file>
                          <file>Langues/lang_pl_PL.qm</file>
                      </qresource>
                  </RCC>
                  
                  
                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #12

                  @DavidM29

                  @J.Hilk said in Deploy QML app to devices with languages files:

                  @DavidM29 please show us how you load the translation file

                  @sierdzio said in Deploy QML app to devices with languages files:

                  Then you need to use proper QRC paths to load the translations (so `":/path/to/file.qm" instead of normal filesystem path).


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  D 1 Reply Last reply
                  0
                  • D DavidM29

                    @sierdzio
                    I did here is my qrc file :

                    <RCC>
                        <qresource prefix="/">
                            <file>Langues/lang_fr_FR.qm</file>
                            <file>Langues/lang_en_US.qm</file>
                            <file>Langues/lang_cz_CZ.qm</file>
                            <file>Langues/lang_da_DA.qm</file>
                            <file>Langues/lang_de_DE.qm</file>
                            <file>Langues/lang_es_ES.qm</file>
                            <file>Langues/lang_pl_PL.qm</file>
                        </qresource>
                    </RCC>
                    
                    
                    sierdzioS Offline
                    sierdzioS Offline
                    sierdzio
                    Moderators
                    wrote on last edited by
                    #13

                    @DavidM29 said in Deploy QML app to devices with languages files:

                    @sierdzio
                    I did here is my qrc file :

                    <RCC>
                        <qresource prefix="/">
                            <file>Langues/lang_fr_FR.qm</file>
                            <file>Langues/lang_en_US.qm</file>
                            <file>Langues/lang_cz_CZ.qm</file>
                            <file>Langues/lang_da_DA.qm</file>
                            <file>Langues/lang_de_DE.qm</file>
                            <file>Langues/lang_es_ES.qm</file>
                            <file>Langues/lang_pl_PL.qm</file>
                        </qresource>
                    </RCC>
                    
                    

                    OK great. Now the paths in your .cpp code have to refer to these files instead of OS filesystem.

                    (Z(:^

                    1 Reply Last reply
                    0
                    • J.HilkJ J.Hilk

                      @DavidM29

                      @J.Hilk said in Deploy QML app to devices with languages files:

                      @DavidM29 please show us how you load the translation file

                      @sierdzio said in Deploy QML app to devices with languages files:

                      Then you need to use proper QRC paths to load the translations (so `":/path/to/file.qm" instead of normal filesystem path).

                      D Offline
                      D Offline
                      DavidM29
                      wrote on last edited by DavidM29
                      #14

                      @J.Hilk
                      Here is the load part in my cpp :

                      !translator->load(
                                      QString("lang_%1").arg(language),
                                      QString("%1/Langues").arg(dir.path())
                                      )
                                  )
                      

                      with dir :

                      QDir dir = QDir(qApp->applicationDirPath()).absolutePath();
                      
                      J.HilkJ 1 Reply Last reply
                      0
                      • D DavidM29

                        @J.Hilk
                        Here is the load part in my cpp :

                        !translator->load(
                                        QString("lang_%1").arg(language),
                                        QString("%1/Langues").arg(dir.path())
                                        )
                                    )
                        

                        with dir :

                        QDir dir = QDir(qApp->applicationDirPath()).absolutePath();
                        
                        J.HilkJ Offline
                        J.HilkJ Offline
                        J.Hilk
                        Moderators
                        wrote on last edited by
                        #15

                        @DavidM29

                        !translator->load(
                        QString("lang_%1").arg(language),
                        QString(":/Langues") )


                        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                        Q: What's that?
                        A: It's blue light.
                        Q: What does it do?
                        A: It turns blue.

                        1 Reply Last reply
                        3
                        • D Offline
                          D Offline
                          DavidM29
                          wrote on last edited by
                          #16

                          Thank you all for your help it was that easy ! If i knew !
                          It works well now that J.Hilk correct the load function.

                          1 Reply Last reply
                          0
                          • Romain CR Offline
                            Romain CR Offline
                            Romain C
                            wrote on last edited by
                            #17

                            It's been a while now, but I will add things on this topic.
                            All proposed solutions made me sceptic as .tr are the sources file (as .cpp) and .qm are binary (as .o). So you're supposed to save the sources on a git, and not theirs binaries (dynamically generated).

                            Based on this assumption, version 5 of Qt introduce :

                            CONFIG += lrelease embed_translations
                            

                            All generated translation binary are then loaded under the prefix "i18n".
                            Best regards

                            1 Reply Last reply
                            2

                            • Login

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