From 242874e705d3002f19bd4f582bcc339f40191733 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sun, 29 May 2022 00:29:45 +0300 Subject: [PATCH] Use CMake to update translation files It uses lupdate directly. Qt's `qt_add_lupdate()` cmake function doesn't help much. First of all it is Qt6 only. Secondly, our project is split into multiple targets but we need all strings into a single .ts file per language. Thirdly, it looks like it will skip source files that are added conditionally into the build via cmake condition checking (eg DBUS source files). We need to gather all strings present in the source files regardless of the build configuration. On another note, this is a step towards reducing dependency on qmake/autoconf. --- src/app/CMakeLists.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 80830c80f..a531f7fd1 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -1,8 +1,19 @@ +file(GLOB QBT_TS_FILES "${qBittorrent_SOURCE_DIR}/src/lang/*.ts") +# Custom target to update .ts files and include new strings from source files +# Depends on Qt's LinguistTools +get_target_property(QT_LUPDATE_EXECUTABLE Qt::lupdate IMPORTED_LOCATION) +add_custom_target(qbt_update_translations + COMMAND ${QT_LUPDATE_EXECUTABLE} -extensions ui,c,c++,cc,cpp,cxx,ch,h,h++,hh,hpp,hxx + ${qBittorrent_SOURCE_DIR} + -ts ${QBT_TS_FILES} + WORKING_DIRECTORY "${qBittorrent_SOURCE_DIR}" + VERBATIM + COMMAND_EXPAND_LISTS) + # Generate and configure translation files # ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------- # Based on https://gist.github.com/giraldeau/546ba5512a74dfe9d8ea0862d66db412 -file(GLOB QBT_TS_FILES "${qBittorrent_SOURCE_DIR}/src/lang/*.ts") set_source_files_properties(${QBT_TS_FILES} PROPERTIES OUTPUT_LOCATION "${qBittorrent_BINARY_DIR}/src/lang") qt_add_translation(QBT_QM_FILES ${QBT_TS_FILES} OPTIONS -silent) configure_file("${qBittorrent_SOURCE_DIR}/src/lang/lang.qrc" "${qBittorrent_BINARY_DIR}/src/lang/lang.qrc" COPYONLY)