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. Qt 6 adding qt_add_translations() to CMake creates empty .ts files.
Forum Updated to NodeBB v4.3 + New Features

Qt 6 adding qt_add_translations() to CMake creates empty .ts files.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 4 Posters 1.0k 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.
  • V Offline
    V Offline
    Vede34
    wrote on last edited by
    #1

    I've been attempting to add support for localization to a project. From the documentation I understand the following CMake should create the template for my .ts filled with the text variables I marked with qsTr("example"). However, it only seems to create an empty .ts file.

    How could I approach fixing this problem?

    The following is a recreation in a test project with simpler files.
    main.qml

    import QtQuick
    
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    }
    

    CMakeLists.txt

    cmake_minimum_required(VERSION 3.16)
    
    project(translatetest VERSION 0.1 LANGUAGES CXX)
    
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    find_package(Qt6 6.2 COMPONENTS Quick LinguistTools REQUIRED)
    
    qt_add_executable(apptranslatetest
        main.cpp
    )
    
    qt_add_qml_module(apptranslatetest
        URI translatetest
        VERSION 1.0
        QML_FILES main.qml 
    )
    
    qt_add_translations(apptranslatetest
        TS_FILES
            translatetest_fi_FI.ts
    )
    
    set_target_properties(apptranslatetest PROPERTIES
        MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
        MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
        MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
        MACOSX_BUNDLE TRUE
        WIN32_EXECUTABLE TRUE
    )
    
    target_link_libraries(apptranslatetest
        PRIVATE Qt6::Quick)
    
    install(TARGETS apptranslatetest
        BUNDLE DESTINATION .
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
    

    After building and running:
    translatetest_fi_FI.ts

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE TS>
    <TS version="2.1" language="fi_FI"></TS>
    
    I 1 Reply Last reply
    1
    • V Vede34

      I've been attempting to add support for localization to a project. From the documentation I understand the following CMake should create the template for my .ts filled with the text variables I marked with qsTr("example"). However, it only seems to create an empty .ts file.

      How could I approach fixing this problem?

      The following is a recreation in a test project with simpler files.
      main.qml

      import QtQuick
      
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      }
      

      CMakeLists.txt

      cmake_minimum_required(VERSION 3.16)
      
      project(translatetest VERSION 0.1 LANGUAGES CXX)
      
      set(CMAKE_AUTOMOC ON)
      set(CMAKE_CXX_STANDARD_REQUIRED ON)
      
      find_package(Qt6 6.2 COMPONENTS Quick LinguistTools REQUIRED)
      
      qt_add_executable(apptranslatetest
          main.cpp
      )
      
      qt_add_qml_module(apptranslatetest
          URI translatetest
          VERSION 1.0
          QML_FILES main.qml 
      )
      
      qt_add_translations(apptranslatetest
          TS_FILES
              translatetest_fi_FI.ts
      )
      
      set_target_properties(apptranslatetest PROPERTIES
          MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
          MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
          MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
          MACOSX_BUNDLE TRUE
          WIN32_EXECUTABLE TRUE
      )
      
      target_link_libraries(apptranslatetest
          PRIVATE Qt6::Quick)
      
      install(TARGETS apptranslatetest
          BUNDLE DESTINATION .
          LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
      

      After building and running:
      translatetest_fi_FI.ts

      <?xml version="1.0" encoding="utf-8"?>
      <!DOCTYPE TS>
      <TS version="2.1" language="fi_FI"></TS>
      
      I Offline
      I Offline
      ikerssm
      wrote on last edited by ikerssm
      #2

      @Vede34
      Hi

      I was having the same issue.

      Seems like in Qtcreator and CMAKE, the target "all" does not include update_translations target.

      Just go to project check it and it will be generated

      V 1 Reply Last reply
      0
      • I ikerssm

        @Vede34
        Hi

        I was having the same issue.

        Seems like in Qtcreator and CMAKE, the target "all" does not include update_translations target.

        Just go to project check it and it will be generated

        V Offline
        V Offline
        veryQTguy
        wrote on last edited by
        #3

        @ikerssm Thank you I would never have come to a solution If I hadn't read this. Such a dumb bug.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AlterX
          wrote last edited by
          #4

          Nice to see that problem is still there using QtCreator 17.0!!!

          Thanks for the solution, it helped me saving extra time (already spent 5 hours with AIs involved as well)

          Qt Ambassador
          Real-time cooperative teams: http://www.softairrealfight.net
          Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

          https://codereview.qt-project.org/...

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AlterX
            wrote last edited by
            #5

            Best solution, independent from changing the targets manually, is to add:
            add_dependencies(${PROJECT_NAME} update_translations)

            Qt Ambassador
            Real-time cooperative teams: http://www.softairrealfight.net
            Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

            https://codereview.qt-project.org/...

            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