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. CMake +Qt6 +lupdate

CMake +Qt6 +lupdate

Scheduled Pinned Locked Moved Solved General and Desktop
cmakelinguist
13 Posts 4 Posters 3.1k 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 6 Dec 2023, 21:24 last edited by
    #2

    Hi,

    Can you show how your CMakeLists.txt file looks like ?

    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 7 Dec 2023, 09:07
    0
    • S SGaist
      6 Dec 2023, 21:24

      Hi,

      Can you show how your CMakeLists.txt file looks like ?

      A Offline
      A Offline
      artwaw
      wrote on 7 Dec 2023, 09:07 last edited by
      #3

      @SGaist Hi, long time no see!

      cmake_minimum_required(VERSION 3.5)
      
      project(CamoGenerator VERSION 0.1 LANGUAGES CXX)
      
      set(CMAKE_AUTOUIC ON)
      set(CMAKE_AUTOMOC ON)
      set(CMAKE_AUTORCC ON)
      
      set(CMAKE_CXX_STANDARD 17)
      set(CMAKE_CXX_STANDARD_REQUIRED ON)
      
      find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Svg LinguistTools)
      find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Svg LinguistTools)
      
      set(DIST_FILES
          COPYING
      )
      
      set(PROJECT_SOURCES
              main.cpp res.qrc
              MainWindow.h MainWindow.cpp MainWindow.ui
              PrefsDialog.h PrefsDialog.cpp PrefsDialog.ui
              AboutDialog.h AboutDialog.cpp AboutDialog.ui
      )
      
      if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
          qt_add_executable(CamoGenerator
              MANUAL_FINALIZATION
              ${PROJECT_SOURCES}
              ${DIST_FILES}
          )
      else()
          add_executable(CamoGenerator
              ${PROJECT_SOURCES}
          )
      endif()
      
      qt_add_translations(CamoGenerator TS_FILES CamoGenerator_en.ts CamoGenerator_pl.ts
          RESOURCE_PREFIX /i18n
          SOURCES ${PROJECT_SOURCES}
          LUPDATE_OPTIONS -source-language en -target-language pl
      )
      
      target_link_libraries(CamoGenerator PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
      target_link_libraries(CamoGenerator PRIVATE Qt${QT_VERSION_MAJOR}::Svg)
      
      if(${QT_VERSION} VERSION_LESS 6.1.0)
        set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER pl.com.trollnet.CamoGenerator)
      endif()
      set_target_properties(CamoGenerator PROPERTIES
          ${BUNDLE_ID_OPTION}
          MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
          MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
          MACOSX_BUNDLE TRUE
          WIN32_EXECUTABLE TRUE
      )
      
      include(GNUInstallDirs)
      install(TARGETS CamoGenerator
          BUNDLE DESTINATION .
          LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
          RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
      )
      
      if(QT_VERSION_MAJOR EQUAL 6)
          qt_finalize_executable(CamoGenerator)
      endif()
      

      I also verified that if run manually, with source files specified, lupdate works.

      For more information please re-read.

      Kind Regards,
      Artur

      K 1 Reply Last reply 7 Dec 2023, 09:11
      0
      • A artwaw
        7 Dec 2023, 09:07

        @SGaist Hi, long time no see!

        cmake_minimum_required(VERSION 3.5)
        
        project(CamoGenerator VERSION 0.1 LANGUAGES CXX)
        
        set(CMAKE_AUTOUIC ON)
        set(CMAKE_AUTOMOC ON)
        set(CMAKE_AUTORCC ON)
        
        set(CMAKE_CXX_STANDARD 17)
        set(CMAKE_CXX_STANDARD_REQUIRED ON)
        
        find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Svg LinguistTools)
        find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Svg LinguistTools)
        
        set(DIST_FILES
            COPYING
        )
        
        set(PROJECT_SOURCES
                main.cpp res.qrc
                MainWindow.h MainWindow.cpp MainWindow.ui
                PrefsDialog.h PrefsDialog.cpp PrefsDialog.ui
                AboutDialog.h AboutDialog.cpp AboutDialog.ui
        )
        
        if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
            qt_add_executable(CamoGenerator
                MANUAL_FINALIZATION
                ${PROJECT_SOURCES}
                ${DIST_FILES}
            )
        else()
            add_executable(CamoGenerator
                ${PROJECT_SOURCES}
            )
        endif()
        
        qt_add_translations(CamoGenerator TS_FILES CamoGenerator_en.ts CamoGenerator_pl.ts
            RESOURCE_PREFIX /i18n
            SOURCES ${PROJECT_SOURCES}
            LUPDATE_OPTIONS -source-language en -target-language pl
        )
        
        target_link_libraries(CamoGenerator PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
        target_link_libraries(CamoGenerator PRIVATE Qt${QT_VERSION_MAJOR}::Svg)
        
        if(${QT_VERSION} VERSION_LESS 6.1.0)
          set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER pl.com.trollnet.CamoGenerator)
        endif()
        set_target_properties(CamoGenerator PROPERTIES
            ${BUNDLE_ID_OPTION}
            MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
            MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
            MACOSX_BUNDLE TRUE
            WIN32_EXECUTABLE TRUE
        )
        
        include(GNUInstallDirs)
        install(TARGETS CamoGenerator
            BUNDLE DESTINATION .
            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
            RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
        )
        
        if(QT_VERSION_MAJOR EQUAL 6)
            qt_finalize_executable(CamoGenerator)
        endif()
        

        I also verified that if run manually, with source files specified, lupdate works.

        K Offline
        K Offline
        kkoehne
        Moderators
        wrote on 7 Dec 2023, 09:11 last edited by
        #4

        @artwaw you need to run the 'update_translations' target at least once from your build system.

        Director R&D, The Qt Company

        K 1 Reply Last reply 7 Dec 2023, 09:18
        1
        • K kkoehne
          7 Dec 2023, 09:11

          @artwaw you need to run the 'update_translations' target at least once from your build system.

          K Offline
          K Offline
          kkoehne
          Moderators
          wrote on 7 Dec 2023, 09:18 last edited by
          #5

          @kkoehne

          qt_add_translations(CamoGenerator TS_FILES CamoGenerator_en.ts CamoGenerator_pl.ts
              RESOURCE_PREFIX /i18n
              SOURCES ${PROJECT_SOURCES}
              LUPDATE_OPTIONS -source-language en -target-language pl
          )
          

          The -target-language option looks wrong, as it makes no sense for CamoGenerator_en.ts. You should be able to just leave it out, actually, as lupdate should be clever enough to figure it out from the file name.

          For CamoGenerator_en.ts, consider passing it by NATIVE_QS_FILE (at least with Qt 6.6):

          qt_add_translations(CamoGenerator 
              TS_FILES CamoGenerator_pl.ts
              NATIVE_TS_FILE CamoGenerator_en.ts 
              RESOURCE_PREFIX /i18n
              SOURCES ${PROJECT_SOURCES}
              LUPDATE_OPTIONS -source-language en
          )
          

          Director R&D, The Qt Company

          A 1 Reply Last reply 7 Dec 2023, 09:29
          1
          • K kkoehne
            7 Dec 2023, 09:18

            @kkoehne

            qt_add_translations(CamoGenerator TS_FILES CamoGenerator_en.ts CamoGenerator_pl.ts
                RESOURCE_PREFIX /i18n
                SOURCES ${PROJECT_SOURCES}
                LUPDATE_OPTIONS -source-language en -target-language pl
            )
            

            The -target-language option looks wrong, as it makes no sense for CamoGenerator_en.ts. You should be able to just leave it out, actually, as lupdate should be clever enough to figure it out from the file name.

            For CamoGenerator_en.ts, consider passing it by NATIVE_QS_FILE (at least with Qt 6.6):

            qt_add_translations(CamoGenerator 
                TS_FILES CamoGenerator_pl.ts
                NATIVE_TS_FILE CamoGenerator_en.ts 
                RESOURCE_PREFIX /i18n
                SOURCES ${PROJECT_SOURCES}
                LUPDATE_OPTIONS -source-language en
            )
            
            A Offline
            A Offline
            artwaw
            wrote on 7 Dec 2023, 09:29 last edited by
            #6

            @kkoehne Hi and thank you for the suggestion.

            The -target-language and other options are the artefacts of me trying to make it work by specifying extra options I never had to use.

            Now with regards to building additional target - build step is:

            cmake --build [path-to-folder]build-CamoGenerator-Qt_6_6_1_for_macOS-Debug --target all
            

            Do I need to specify an additional build step now? This used to be more straightforward (and better documented) in the past.

            For more information please re-read.

            Kind Regards,
            Artur

            K 1 Reply Last reply 7 Dec 2023, 09:31
            0
            • A artwaw
              7 Dec 2023, 09:29

              @kkoehne Hi and thank you for the suggestion.

              The -target-language and other options are the artefacts of me trying to make it work by specifying extra options I never had to use.

              Now with regards to building additional target - build step is:

              cmake --build [path-to-folder]build-CamoGenerator-Qt_6_6_1_for_macOS-Debug --target all
              

              Do I need to specify an additional build step now? This used to be more straightforward (and better documented) in the past.

              K Offline
              K Offline
              kkoehne
              Moderators
              wrote on 7 Dec 2023, 09:31 last edited by
              #7

              Try to do a

              cmake --build [path-to-folder]build-CamoGenerator-Qt_6_6_1_for_macOS-Debug --target update_translations
              

              first. Maybe it works also in one go, though I'm not sure:

              cmake --build [path-to-folder]build-CamoGenerator-Qt_6_6_1_for_macOS-Debug --target all update_translations
              

              The idea is that you don't want to run lupdate on every call, only at certain times, when you're actually ready to do the translations. So that why the target is not a default one.

              Director R&D, The Qt Company

              A 1 Reply Last reply 7 Dec 2023, 09:37
              1
              • K kkoehne
                7 Dec 2023, 09:31

                Try to do a

                cmake --build [path-to-folder]build-CamoGenerator-Qt_6_6_1_for_macOS-Debug --target update_translations
                

                first. Maybe it works also in one go, though I'm not sure:

                cmake --build [path-to-folder]build-CamoGenerator-Qt_6_6_1_for_macOS-Debug --target all update_translations
                

                The idea is that you don't want to run lupdate on every call, only at certain times, when you're actually ready to do the translations. So that why the target is not a default one.

                A Offline
                A Offline
                artwaw
                wrote on 7 Dec 2023, 09:37 last edited by
                #8

                @kkoehne That did a trick, thank you. I am not sure I appreciate the extra hoops one needs to go through to have the result but I got it working.

                NATIVE_TS_FILE is something I'd need to read on, is there any documentation? I could not find it in the help system.

                At any rate, marking this as solved, thank you a thousand times!

                For more information please re-read.

                Kind Regards,
                Artur

                K 1 Reply Last reply 7 Dec 2023, 10:11
                0
                • A artwaw has marked this topic as solved on 7 Dec 2023, 09:37
                • A artwaw
                  7 Dec 2023, 09:37

                  @kkoehne That did a trick, thank you. I am not sure I appreciate the extra hoops one needs to go through to have the result but I got it working.

                  NATIVE_TS_FILE is something I'd need to read on, is there any documentation? I could not find it in the help system.

                  At any rate, marking this as solved, thank you a thousand times!

                  K Offline
                  K Offline
                  kkoehne
                  Moderators
                  wrote on 7 Dec 2023, 10:11 last edited by
                  #9

                  @artwaw said in CMake +Qt6 +lupdate:

                  I am not sure I appreciate the extra hoops one needs to go through to have the result but I got it working.

                  Yeah, it's a tad ugly. You should have gotten a warning like

                  Translation file '`CamoGenerator_en.ts' does not exist. Consider building the target 'update_translations' to create an initial version of that file.
                  

                  on the first run though?

                  Director R&D, The Qt Company

                  A 1 Reply Last reply 7 Dec 2023, 10:19
                  0
                  • K kkoehne
                    7 Dec 2023, 10:11

                    @artwaw said in CMake +Qt6 +lupdate:

                    I am not sure I appreciate the extra hoops one needs to go through to have the result but I got it working.

                    Yeah, it's a tad ugly. You should have gotten a warning like

                    Translation file '`CamoGenerator_en.ts' does not exist. Consider building the target 'update_translations' to create an initial version of that file.
                    

                    on the first run though?

                    A Offline
                    A Offline
                    artwaw
                    wrote on 7 Dec 2023, 10:19 last edited by
                    #10

                    @kkoehne Not with my initial setup. After I altered the add_translations line to match your suggestion it indeed popped up but then I was already making changes to the build command.

                    For more information please re-read.

                    Kind Regards,
                    Artur

                    K 1 Reply Last reply 7 Dec 2023, 11:14
                    0
                    • A artwaw
                      7 Dec 2023, 10:19

                      @kkoehne Not with my initial setup. After I altered the add_translations line to match your suggestion it indeed popped up but then I was already making changes to the build command.

                      K Offline
                      K Offline
                      kkoehne
                      Moderators
                      wrote on 7 Dec 2023, 11:14 last edited by
                      #11

                      @artwaw said in CMake +Qt6 +lupdate:

                      Not with my initial setup. After I altered the add_translations line to match your suggestion it indeed popped up but then I was already making changes to the build command.

                      Weird. I'll try to replicate this...

                      Btw, seeing your original CMakeLists.txt file: It seems you want to keep compatibility with older Qt 6 versions, and even Qt 5. Please note that qt_add_translations() was only added to Qt 6.2, so you might need to guard it by an Qt version check. And the NATIVE_TS_FILE option only will actually appear in Qt 6.7: https://doc-snapshots.qt.io/qt6-dev/qtlinguist-cmake-qt-add-translations.html

                      Director R&D, The Qt Company

                      A ekkescornerE 2 Replies Last reply 7 Dec 2023, 11:22
                      1
                      • K kkoehne
                        7 Dec 2023, 11:14

                        @artwaw said in CMake +Qt6 +lupdate:

                        Not with my initial setup. After I altered the add_translations line to match your suggestion it indeed popped up but then I was already making changes to the build command.

                        Weird. I'll try to replicate this...

                        Btw, seeing your original CMakeLists.txt file: It seems you want to keep compatibility with older Qt 6 versions, and even Qt 5. Please note that qt_add_translations() was only added to Qt 6.2, so you might need to guard it by an Qt version check. And the NATIVE_TS_FILE option only will actually appear in Qt 6.7: https://doc-snapshots.qt.io/qt6-dev/qtlinguist-cmake-qt-add-translations.html

                        A Offline
                        A Offline
                        artwaw
                        wrote on 7 Dec 2023, 11:22 last edited by
                        #12

                        @kkoehne Thank you for the docs link - that all makes much more sense now!

                        As for backward compatibility - no, I don't intent on keeping that, simply didn't clean the autogenerated template yet. I'll bear in mind narrowing the checks to ver=>6.2 though.

                        Again, many thanks for sharing the knowledge!

                        For more information please re-read.

                        Kind Regards,
                        Artur

                        1 Reply Last reply
                        0
                        • K kkoehne
                          7 Dec 2023, 11:14

                          @artwaw said in CMake +Qt6 +lupdate:

                          Not with my initial setup. After I altered the add_translations line to match your suggestion it indeed popped up but then I was already making changes to the build command.

                          Weird. I'll try to replicate this...

                          Btw, seeing your original CMakeLists.txt file: It seems you want to keep compatibility with older Qt 6 versions, and even Qt 5. Please note that qt_add_translations() was only added to Qt 6.2, so you might need to guard it by an Qt version check. And the NATIVE_TS_FILE option only will actually appear in Qt 6.7: https://doc-snapshots.qt.io/qt6-dev/qtlinguist-cmake-qt-add-translations.html

                          ekkescornerE Offline
                          ekkescornerE Offline
                          ekkescorner
                          Qt Champions 2016
                          wrote on 19 Jan 2024, 16:56 last edited by ekkescorner
                          #13

                          @kkoehne said in CMake +Qt6 +lupdate:
                          cool - sounds to become easier and more flexible in 6.7. will test with beta2

                          And the NATIVE_TS_FILE option only will actually appear in Qt 6.7: https://doc-snapshots.qt.io/qt6-dev/qtlinguist-cmake-qt-add-translations.html

                          I'm developing always in english, where in most cases german is used by customers. Because I'm writing code in 'developer-english' it may happen, that customer requests to change a translation. for these cases and to handle plural forms I always also add an en ts file, so I'm using
                          .ts / _de.ts / _en.ts / _fr.ts ...
                          this is working well because translations not found in _en.ts will come from .ts
                          seems that in this case I don't have to set the NATIVE_TS_FILE, because _en.ts not only contains plural forms ?

                          if setting QT_I18N_LANGUAGES will this work if my (from Qt 5.15 ported) .ts files are in project_dir/translations ?

                          BTW: the lrelease command is executed automatically if building in QtCreator ?
                          In 5.15 my workflow was: lupdate, Linguist, lrelease
                          Now in 6.7 I can do lupdate automatically with add_dependencies(...lupdate) or execute manually with CMD-K cm ...lupdate and lrelease is always done automagically ?

                          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

                          • Login

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