translation files with CMake
-
Hello. I have spent best part of two days trying to figure how to create and fill the translation files of my QtQuick app made using CMake, but frankly, I do not want to sound rude, but the documentation is awful. No where it has a step by step explanation of what I need to do, just documentation of a few macros with no mention of why I would need one or another.
I have changed all my strings that need to be translated for the qsTr form and added a the add_Translations macro to my cmake file as below is shown. But NOTHING happens when I make the build, no strings are collected, the ts files are not touched. The QtCreator external linguist tool simply refuses to do anything when I am using a CMAKE project.
Can anyone point me into a proper tuturial of how to make the linguist tools work with a Cmake project?
cmake_minimum_required(VERSION 3.16) project(aquila_companion VERSION 0.1 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 6.4 REQUIRED COMPONENTS QuickControls2 Quick LinguistTools) qt_standard_project_setup() qt_add_executable(appaquila_companion main.cpp aquila_backend.h httprequestworker.h httprequestworker.cpp aquila_backend.cpp restworker.h restworker.cpp lang/base.ts lang/qml_en.ts lang/qml_br.ts ) qt_add_qml_module(appaquila_companion URI aquila_companion VERSION 1.0 QML_FILES Main.qml components/Evaluationitem.qml components/Worklistitem.qml components/Starlike.qml components/Ratingstar.qml RESOURCES resources/plus.png resources/bullet.png resources/performance.png resources/user-solid-2.png resources/hashtag-solid.png resources/calendar-regular.png resources/star.png resources/aquila_dark_back.png resources/aquila_light_back.png resources/aquila_mono_main.png resources/aquila_brand_mono_white.png Montserrat-Regular.ttf components/Worklistitem.qml ) qt_add_translations(appaquila_companion TS_FILES lang/base.ts lang/qml_en.ts lang/qml_pt_BR.ts ) set_target_properties(appaquila_companion 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(appaquila_companion PRIVATE Qt6::Quick ) install(TARGETS appaquila_companion BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
-
Hello. I have spent best part of two days trying to figure how to create and fill the translation files of my QtQuick app made using CMake, but frankly, I do not want to sound rude, but the documentation is awful. No where it has a step by step explanation of what I need to do, just documentation of a few macros with no mention of why I would need one or another.
I have changed all my strings that need to be translated for the qsTr form and added a the add_Translations macro to my cmake file as below is shown. But NOTHING happens when I make the build, no strings are collected, the ts files are not touched. The QtCreator external linguist tool simply refuses to do anything when I am using a CMAKE project.
Can anyone point me into a proper tuturial of how to make the linguist tools work with a Cmake project?
cmake_minimum_required(VERSION 3.16) project(aquila_companion VERSION 0.1 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 6.4 REQUIRED COMPONENTS QuickControls2 Quick LinguistTools) qt_standard_project_setup() qt_add_executable(appaquila_companion main.cpp aquila_backend.h httprequestworker.h httprequestworker.cpp aquila_backend.cpp restworker.h restworker.cpp lang/base.ts lang/qml_en.ts lang/qml_br.ts ) qt_add_qml_module(appaquila_companion URI aquila_companion VERSION 1.0 QML_FILES Main.qml components/Evaluationitem.qml components/Worklistitem.qml components/Starlike.qml components/Ratingstar.qml RESOURCES resources/plus.png resources/bullet.png resources/performance.png resources/user-solid-2.png resources/hashtag-solid.png resources/calendar-regular.png resources/star.png resources/aquila_dark_back.png resources/aquila_light_back.png resources/aquila_mono_main.png resources/aquila_brand_mono_white.png Montserrat-Regular.ttf components/Worklistitem.qml ) qt_add_translations(appaquila_companion TS_FILES lang/base.ts lang/qml_en.ts lang/qml_pt_BR.ts ) set_target_properties(appaquila_companion 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(appaquila_companion PRIVATE Qt6::Quick ) install(TARGETS appaquila_companion BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
Please read the documentation of the macro. It creates additional targets which you have to execute when the ts files should be updated.
-
Please read the documentation of the macro. It creates additional targets which you have to execute when the ts files should be updated.
@Christian-Ehrlicher Sorry but that helps in nothing, really absolutely NOTHING.
I have read the documentation of all the macros listed and that documentation is borderline useless for someone trying to understand the process for the first time.
The documentations are just isolated lines like "Calls lrelease on each .ts file passed as an argument, generating .qm files. The paths of the generated files are added to <VAR>." This means absolutely.. nothing for me.
I do not know what targets I need, or what I need them for! There is not a single example with all the needed macros being used as they should be used. I do not know how they relate and the meaning of what they are supposed to create.
When I try adding the Macros one by one just replacing the project name and filenames. nothing happens on build. and I do not even know if it should happen on build because nothing explains when these will be used. I Download the code from QtExamples and still there is zero evidence of how the .ts files are created so I can send them to the translation team.
The process itself needs a better documentation.
-
Linguist comes with a few examples which are used to generate the documentation. Arrow Pad is one of them.
I just opened up Qt Creator and in the Welcome to Qt Creator pane I've went to Examples and typed linguist and found the Arrow Pad example.
Configured with a Qt 6.5.1 MSVC 2019 kit:
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - not found -- Looking for pthread_create in pthread -- Looking for pthread_create in pthread - not found -- Found Threads: TRUE -- Performing Test HAVE_STDATOMIC -- Performing Test HAVE_STDATOMIC - Success -- Found WrapAtomic: TRUE -- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) CMake Warning at C:/Qt/6.5.1/msvc2019_64/lib/cmake/Qt6LinguistTools/Qt6LinguistToolsMacros.cmake:221 (message): Translation file 'C:/Qt/Examples/Qt-6.5.1/linguist/arrowpad/arrowpad_fr.ts' does not exist. Consider building the target 'arrowpad_lupdate' to create an initial version of that file. Call Stack (most recent call first): C:/Qt/6.5.1/msvc2019_64/lib/cmake/Qt6LinguistTools/Qt6LinguistToolsMacros.cmake:333 (qt6_add_lrelease) CMakeLists.txt:28 (qt6_add_translations) CMake Warning at C:/Qt/6.5.1/msvc2019_64/lib/cmake/Qt6LinguistTools/Qt6LinguistToolsMacros.cmake:221 (message): Translation file 'C:/Qt/Examples/Qt-6.5.1/linguist/arrowpad/arrowpad_nl.ts' does not exist. Consider building the target 'arrowpad_lupdate' to create an initial version of that file. Call Stack (most recent call first): C:/Qt/6.5.1/msvc2019_64/lib/cmake/Qt6LinguistTools/Qt6LinguistToolsMacros.cmake:333 (qt6_add_lrelease) CMakeLists.txt:28 (qt6_add_translations) -- Configuring done (6.2s) -- Generating done (0.0s) -- Build files have been written to: C:/Qt/Examples/Qt-6.5.1/linguist/build-arrowpad-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug Elapsed time: 00:07.
Then I've build the example:
17:28:37: Running steps for project arrowpad... 17:28:37: Starting: "C:\Program Files\CMake\bin\cmake.exe" --build C:/Qt/Examples/Qt-6.5.1/linguist/build-arrowpad-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug --target all [1/10 5.6/sec] Generating C:/Qt/Examples/Qt-6.5.1/linguist/arrowpad/arrowpad_nl.ts Updating '../arrowpad/arrowpad_nl.ts'... Found 0 source text(s) (0 new and 0 already existing) [2/10 10.7/sec] Generating C:/Qt/Examples/Qt-6.5.1/linguist/arrowpad/arrowpad_fr.ts Updating '../arrowpad/arrowpad_fr.ts'... Found 0 source text(s) (0 new and 0 already existing) [3/10 12.5/sec] Generating arrowpad_nl.qm Updating 'C:/Qt/Examples/Qt-6.5.1/linguist/build-arrowpad-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/arrowpad_nl.qm'... Generated 0 translation(s) (0 finished and 0 unfinished) [4/10 15.9/sec] Generating arrowpad_fr.qm Updating 'C:/Qt/Examples/Qt-6.5.1/linguist/build-arrowpad-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/arrowpad_fr.qm'... Generated 0 translation(s) (0 finished and 0 unfinished) [5/10 7.8/sec] Automatic MOC for target arrowpad [6/10 2.5/sec] Building CXX object CMakeFiles\arrowpad.dir\arrowpad_autogen\mocs_compilation.cpp.obj [7/10 1.4/sec] Building CXX object CMakeFiles\arrowpad.dir\main.cpp.obj [8/10 1.6/sec] Building CXX object CMakeFiles\arrowpad.dir\arrowpad.cpp.obj [9/10 1.8/sec] Building CXX object CMakeFiles\arrowpad.dir\mainwindow.cpp.obj [10/10 1.8/sec] Linking CXX executable arrowpad.exe 17:28:43: The process "C:\Program Files\CMake\bin\cmake.exe" exited normally. 17:28:43: Elapsed time: 00:06.
As you can see translations were generated.
-
Linguist comes with a few examples which are used to generate the documentation. Arrow Pad is one of them.
I just opened up Qt Creator and in the Welcome to Qt Creator pane I've went to Examples and typed linguist and found the Arrow Pad example.
Configured with a Qt 6.5.1 MSVC 2019 kit:
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - not found -- Looking for pthread_create in pthread -- Looking for pthread_create in pthread - not found -- Found Threads: TRUE -- Performing Test HAVE_STDATOMIC -- Performing Test HAVE_STDATOMIC - Success -- Found WrapAtomic: TRUE -- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) CMake Warning at C:/Qt/6.5.1/msvc2019_64/lib/cmake/Qt6LinguistTools/Qt6LinguistToolsMacros.cmake:221 (message): Translation file 'C:/Qt/Examples/Qt-6.5.1/linguist/arrowpad/arrowpad_fr.ts' does not exist. Consider building the target 'arrowpad_lupdate' to create an initial version of that file. Call Stack (most recent call first): C:/Qt/6.5.1/msvc2019_64/lib/cmake/Qt6LinguistTools/Qt6LinguistToolsMacros.cmake:333 (qt6_add_lrelease) CMakeLists.txt:28 (qt6_add_translations) CMake Warning at C:/Qt/6.5.1/msvc2019_64/lib/cmake/Qt6LinguistTools/Qt6LinguistToolsMacros.cmake:221 (message): Translation file 'C:/Qt/Examples/Qt-6.5.1/linguist/arrowpad/arrowpad_nl.ts' does not exist. Consider building the target 'arrowpad_lupdate' to create an initial version of that file. Call Stack (most recent call first): C:/Qt/6.5.1/msvc2019_64/lib/cmake/Qt6LinguistTools/Qt6LinguistToolsMacros.cmake:333 (qt6_add_lrelease) CMakeLists.txt:28 (qt6_add_translations) -- Configuring done (6.2s) -- Generating done (0.0s) -- Build files have been written to: C:/Qt/Examples/Qt-6.5.1/linguist/build-arrowpad-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug Elapsed time: 00:07.
Then I've build the example:
17:28:37: Running steps for project arrowpad... 17:28:37: Starting: "C:\Program Files\CMake\bin\cmake.exe" --build C:/Qt/Examples/Qt-6.5.1/linguist/build-arrowpad-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug --target all [1/10 5.6/sec] Generating C:/Qt/Examples/Qt-6.5.1/linguist/arrowpad/arrowpad_nl.ts Updating '../arrowpad/arrowpad_nl.ts'... Found 0 source text(s) (0 new and 0 already existing) [2/10 10.7/sec] Generating C:/Qt/Examples/Qt-6.5.1/linguist/arrowpad/arrowpad_fr.ts Updating '../arrowpad/arrowpad_fr.ts'... Found 0 source text(s) (0 new and 0 already existing) [3/10 12.5/sec] Generating arrowpad_nl.qm Updating 'C:/Qt/Examples/Qt-6.5.1/linguist/build-arrowpad-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/arrowpad_nl.qm'... Generated 0 translation(s) (0 finished and 0 unfinished) [4/10 15.9/sec] Generating arrowpad_fr.qm Updating 'C:/Qt/Examples/Qt-6.5.1/linguist/build-arrowpad-Desktop_Qt_6_5_1_MSVC2019_64bit-Debug/arrowpad_fr.qm'... Generated 0 translation(s) (0 finished and 0 unfinished) [5/10 7.8/sec] Automatic MOC for target arrowpad [6/10 2.5/sec] Building CXX object CMakeFiles\arrowpad.dir\arrowpad_autogen\mocs_compilation.cpp.obj [7/10 1.4/sec] Building CXX object CMakeFiles\arrowpad.dir\main.cpp.obj [8/10 1.6/sec] Building CXX object CMakeFiles\arrowpad.dir\arrowpad.cpp.obj [9/10 1.8/sec] Building CXX object CMakeFiles\arrowpad.dir\mainwindow.cpp.obj [10/10 1.8/sec] Linking CXX executable arrowpad.exe 17:28:43: The process "C:\Program Files\CMake\bin\cmake.exe" exited normally. 17:28:43: Elapsed time: 00:06.
As you can see translations were generated.
@cristian-adam Jist tried same example (QTcreator 10.0.2) and nothing was generated without any error message. Justt running the cmake should do that as in your example?
-
@cristian-adam Jist tried same example (QTcreator 10.0.2) and nothing was generated without any error message. Justt running the cmake should do that as in your example?
Which CMake version are you using?