From 872994b5e5c15a5fc069b50cb2d5e1567aa1f7b7 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Wed, 2 Nov 2022 10:14:19 +0100 Subject: CMake/translations: Use lconvert for cleaning ts files For the translation process it is nice to keep obsolete items and locations, but we do not want these submitted in the end. So while translating we'd have patches: 1. lupdate cleaned of obsolete and line numbers 2. wip: lupdate with obsolete and line numbers 3. translation of plugin X 4. translation of plugin Y and before submitting we want to remove the wip patch (2). But, running lupdate with "-no-obsolete -locations none" for cleaning the ts file has a slightly different sorting than without it, which leads to conflicts when removing the wip patch (2). Instead run lupdate with obsolete items and line numbers first, and clean the ts file with lconvert afterwards. That keeps the diff between patch (1) and (2) minimal, and results in a clean rebase process when removing patch (2). Change-Id: I3b8ac7c30dc6eb0e501be765eb6e64069007a5bd Reviewed-by: Cristian Adam Reviewed-by: Qt CI Bot Reviewed-by: --- cmake/QtCreatorTranslations.cmake | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/cmake/QtCreatorTranslations.cmake b/cmake/QtCreatorTranslations.cmake index cd50d72f10..2fb3f79982 100644 --- a/cmake/QtCreatorTranslations.cmake +++ b/cmake/QtCreatorTranslations.cmake @@ -97,12 +97,23 @@ function(_create_ts_custom_target name) DEPENDS ${_sources} VERBATIM) - add_custom_target("${_arg_TS_TARGET_PREFIX}${name}_cleaned" - COMMAND Qt5::lupdate -locations relative -no-ui-lines -no-sort -no-obsolete -locations none "@${ts_file_list}" -ts ${ts_files} - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" - COMMENT "Generate .ts files, remove obsolete and vanished translations, and do not add files and line number" - DEPENDS ${_sources} - VERBATIM) + # Add cleaned target only for single-ts targets + # Uses lupdate + convert instead of just lupdate with '-locations none -no-obsolete' + # to keep the same sorting as the non-'cleaned' target and therefore keep the diff small + list(LENGTH ts_files file_count) + if(file_count EQUAL 1) + # get path for lconvert... + get_target_property(_lupdate_binary Qt5::lupdate IMPORTED_LOCATION) + get_filename_component(_bin_dir ${_lupdate_binary} DIRECTORY) + + add_custom_target("${_arg_TS_TARGET_PREFIX}${name}_cleaned" + COMMAND Qt5::lupdate -locations relative -no-ui-lines -no-sort "@${ts_file_list}" -ts ${ts_files} + COMMAND ${_bin_dir}/lconvert -locations none -no-ui-lines -no-obsolete ${ts_files} -o ${ts_files} + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + COMMENT "Generate .ts files, remove obsolete and vanished translations, and do not add files and line number" + DEPENDS ${_sources} + VERBATIM) + endif() endfunction() function(add_translation_targets file_prefix) -- cgit v1.2.1