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. Is this the correct way to generate translations with cmake?
Forum Updated to NodeBB v4.3 + New Features

Is this the correct way to generate translations with cmake?

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 2.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.
  • C Creaperdown

    Is this the correct way to generate translations with cmake?

    set(translation_files
        translations/librum_en.ts
        translations/librum_de.ts
        translations/librum_ru.ts
        translations/librum_zh.ts
    )
    
    # Translations for the application
    qt_add_translations(presentation TS_FILES ${translation_files})
    add_dependencies(presentation presentation_lupdate)
    add_dependencies(presentation presentation_lrelease)
    add_dependencies(presentation update_translations)
    
    kkoehneK Offline
    kkoehneK Offline
    kkoehne
    Moderators
    wrote on last edited by kkoehne
    #2

    @Creaperdown the qt_add_translations() call looks straighforward. But why did you feel the need to add the manual add_dependencies?

    add_dependencies(presentation presentation_lupdate)

    This would mean that the source side of the .ts file is updated in every build by running lupdate. This is an unusual setup; you typically want to update the .ts files only at certain times (e.g. if you actually want to start updating the translation).

    add_dependencies(presentation presentation_lrelease)

    This should be unnecessary, as qt_add_translations adds such a dependency.

    add_dependencies(presentation update_translations)

    This is just the same as add_dependencies(presentation presentation_lupdate), as long as you don't add more qt_add_translations calls to other targets.

    Director R&D, The Qt Company

    C 1 Reply Last reply
    0
    • kkoehneK kkoehne

      @Creaperdown the qt_add_translations() call looks straighforward. But why did you feel the need to add the manual add_dependencies?

      add_dependencies(presentation presentation_lupdate)

      This would mean that the source side of the .ts file is updated in every build by running lupdate. This is an unusual setup; you typically want to update the .ts files only at certain times (e.g. if you actually want to start updating the translation).

      add_dependencies(presentation presentation_lrelease)

      This should be unnecessary, as qt_add_translations adds such a dependency.

      add_dependencies(presentation update_translations)

      This is just the same as add_dependencies(presentation presentation_lupdate), as long as you don't add more qt_add_translations calls to other targets.

      C Offline
      C Offline
      Creaperdown
      wrote on last edited by
      #3

      @kkoehne From what I understood:

      add_dependencies(presentation presentation_lupdate)
      

      Is regenerating the ts files from my source code. Since I am doing quite a lot of changes to the front-end of my application, which includes adding new text, I thought that this would always keep my ts files up to date with my application. Or did I understand this incorrectly?

      Christian EhrlicherC 1 Reply Last reply
      0
      • C Creaperdown

        @kkoehne From what I understood:

        add_dependencies(presentation presentation_lupdate)
        

        Is regenerating the ts files from my source code. Since I am doing quite a lot of changes to the front-end of my application, which includes adding new text, I thought that this would always keep my ts files up to date with my application. Or did I understand this incorrectly?

        Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @Creaperdown said in Is this the correct way to generate translations with cmake?:

        I thought that this would always keep my ts files up to date with my application. Or did I understand this incorrectly?

        You're correct that you update your ts files on every compile run but what's the point of this - do you also update all your translations with linguist after each compile run?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        C 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @Creaperdown said in Is this the correct way to generate translations with cmake?:

          I thought that this would always keep my ts files up to date with my application. Or did I understand this incorrectly?

          You're correct that you update your ts files on every compile run but what's the point of this - do you also update all your translations with linguist after each compile run?

          C Offline
          C Offline
          Creaperdown
          wrote on last edited by Creaperdown
          #5

          @Christian-Ehrlicher So your suggestion would be manually running lupdate whenever I change my translation and just changing my code to:

          set(translation_files
              translations/librum_en.ts
              translations/librum_de.ts
              translations/librum_ru.ts
              translations/librum_zh.ts
          )
          
          # Translations for the application
          qt_add_translations(presentation TS_FILES ${translation_files})
          

          ?

          Christian EhrlicherC 1 Reply Last reply
          0
          • C Creaperdown

            @Christian-Ehrlicher So your suggestion would be manually running lupdate whenever I change my translation and just changing my code to:

            set(translation_files
                translations/librum_en.ts
                translations/librum_de.ts
                translations/librum_ru.ts
                translations/librum_zh.ts
            )
            
            # Translations for the application
            qt_add_translations(presentation TS_FILES ${translation_files})
            

            ?

            Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @Creaperdown Yes 🙂
            Iirc there should also be a menu entry in QtCreator to update the translations

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            C 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              @Creaperdown Yes 🙂
              Iirc there should also be a menu entry in QtCreator to update the translations

              C Offline
              C Offline
              Creaperdown
              wrote on last edited by
              #7

              @Christian-Ehrlicher Even after reading the docs, I am not entirely sure what qt_add_translations does. Does it already generate the .qm files? I have removed all the add_dependencies(...) stuff but my cmake output still shows me that the .qm files are generated. Does it also automatically update the .ts files?

              Christian EhrlicherC 1 Reply Last reply
              0
              • C Creaperdown

                @Christian-Ehrlicher Even after reading the docs, I am not entirely sure what qt_add_translations does. Does it already generate the .qm files? I have removed all the add_dependencies(...) stuff but my cmake output still shows me that the .qm files are generated. Does it also automatically update the .ts files?

                Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #8

                qt_add_translations() creates qm files out of the ts files and adds those ts files to the target (created with add_executable/add_library) so they are regenerated on every built of this target when needed (= when the ts files changed in some way). So as long as you don't touch the ts files the qm files should not be regenerated. If so we have to take a look on it.
                Additionally this function creates ${target}_lrelease, update_translation which you can call manually to update the ts files.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                C 1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  qt_add_translations() creates qm files out of the ts files and adds those ts files to the target (created with add_executable/add_library) so they are regenerated on every built of this target when needed (= when the ts files changed in some way). So as long as you don't touch the ts files the qm files should not be regenerated. If so we have to take a look on it.
                  Additionally this function creates ${target}_lrelease, update_translation which you can call manually to update the ts files.

                  C Offline
                  C Offline
                  Creaperdown
                  wrote on last edited by
                  #9

                  @Christian-Ehrlicher Ok, so in short it generates qm files out of the ts files, but doesn't automatically update the ts files when strings in the source code change?

                  Christian EhrlicherC 1 Reply Last reply
                  0
                  • C Creaperdown

                    @Christian-Ehrlicher Ok, so in short it generates qm files out of the ts files, but doesn't automatically update the ts files when strings in the source code change?

                    Christian EhrlicherC Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @Creaperdown Yes

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    C 1 Reply Last reply
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      @Creaperdown Yes

                      C Offline
                      C Offline
                      Creaperdown
                      wrote on last edited by
                      #11

                      @Christian-Ehrlicher Thanks! This answered all my questions, I'll close the issue.

                      1 Reply Last reply
                      2
                      • C Creaperdown has marked this topic as solved on

                      • Login

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