Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use lxqt-transupdate to update translations in cmake #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 10 additions & 53 deletions cmake/modules/LXQtTranslateTs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@
#=============================================================================
#
# funtion lxqt_translate_ts(qmFiles
# [USE_QT5 [Yes | No]]
# [UPDATE_TRANSLATIONS [Yes | No]]
# SOURCES <sources>
# [UPDATE_OPTIONS] update_options
# [TEMPLATE] translation_template
# [TRANSLATION_DIR] translation_directory
# [INSTALL_DIR] install_directory
Expand All @@ -39,15 +37,10 @@
# qmFiles The generated compiled translations (.qm) files
#
# Input:
# USE_QT5 Optional flag to choose between Qt4 and Qt5. Defaults to Qt5
#
# UPDATE_TRANSLATIONS Optional flag. Setting it to Yes, extracts and
# compiles the translations. Setting it No, only
# compiles them.
#
# UPDATE_OPTIONS Optional options to lupdate when UPDATE_TRANSLATIONS
# is True.
#
# TEMPLATE Optional translations files base name. Defaults to
# ${PROJECT_NAME}. An .ts extensions is added.
#
Expand All @@ -67,28 +60,19 @@ include(Qt5PatchedLinguistToolsMacros)

function(lxqt_translate_ts qmFiles)
set(oneValueArgs
USE_QT5
UPDATE_TRANSLATIONS
TEMPLATE
TRANSLATION_DIR
INSTALL_DIR
COMPONENT
)
set(multiValueArgs SOURCES UPDATE_OPTIONS)
set(multiValueArgs SOURCES)
cmake_parse_arguments(TR "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if (NOT DEFINED TR_UPDATE_TRANSLATIONS)
set(TR_UPDATE_TRANSLATIONS "No")
endif()

if (NOT DEFINED TR_UPDATE_OPTIONS)
set(TR_UPDATE_OPTIONS "")
endif()

if (NOT DEFINED TR_USE_QT5)
set(TR_USE_QT5 "Yes")
endif()

if(NOT DEFINED TR_TEMPLATE)
set(TR_TEMPLATE "${PROJECT_NAME}")
endif()
Expand All @@ -103,43 +87,16 @@ function(lxqt_translate_ts qmFiles)
set(templateFile "${TR_TRANSLATION_DIR}/${TR_TEMPLATE}.ts")
endif ()

if(TR_USE_QT5)
# Qt5
if (TR_UPDATE_TRANSLATIONS)
qt5_patched_create_translation(QMS
${TR_SOURCES}
${templateFile}
OPTIONS ${TR_UPDATE_OPTIONS}
)
qt5_patched_create_translation(QM
${TR_SOURCES}
${tsFiles}
OPTIONS ${TR_UPDATE_OPTIONS}
)
else()
qt5_patched_add_translation(QM ${tsFiles})
endif()
else()
# Qt4
if(TR_UPDATE_TRANSLATIONS)
qt4_create_translation(QMS
${TR_SOURCES}
${templateFile}
OPTIONS ${TR_UPDATE_OPTIONS}
)
qt4_create_translation(QM
${TR_SOURCES}
${tsFiles}
OPTIONS ${TR_UPDATE_OPTIONS}
)
else()
qt4_add_translation(QM ${tsFiles})
endif()
endif()

if(TR_UPDATE_TRANSLATIONS)
add_custom_target("update_${TR_TEMPLATE}_ts" ALL DEPENDS ${QMS})
if (TR_UPDATE_TRANSLATIONS)
message("Running lxqt-transupdate: ")
execute_process(
COMMAND lxqt-transupdate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should change the logic of getting sources and ts files in lxqt-transupdate and use here the ${TR_SOURCES} and ${tsFiles} .... so the configuration is exactly on one place (not in CMakeLists.txt together with .translation-update)

WORKING_DIRECTORY ..
OUTPUT_VARIABLE outVar
)
message(${outVar})
endif()
qt5_patched_add_translation(QM ${tsFiles})

if(DEFINED TR_INSTALL_DIR)
if(NOT DEFINED TR_COMPONENT)
Expand Down
53 changes: 0 additions & 53 deletions cmake/modules/Qt5PatchedLinguistToolsMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,59 +32,6 @@

include(CMakeParseArguments)

function(QT5_PATCHED_CREATE_TRANSLATION _qm_files)
set(options)
set(oneValueArgs)
set(multiValueArgs OPTIONS)

cmake_parse_arguments(_LUPDATE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(_lupdate_files ${_LUPDATE_UNPARSED_ARGUMENTS})
set(_lupdate_options ${_LUPDATE_OPTIONS})

set(_my_sources)
set(_my_tsfiles)
foreach(_file ${_lupdate_files})
get_filename_component(_ext ${_file} EXT)
get_filename_component(_abs_FILE ${_file} ABSOLUTE)
if(_ext MATCHES "ts")
list(APPEND _my_tsfiles ${_abs_FILE})
else()
list(APPEND _my_sources ${_abs_FILE})
endif()
endforeach()
foreach(_ts_file ${_my_tsfiles})
if(_my_sources)
# make a list file to call lupdate on, so we don't make our commands too
# long for some systems
# get_filename_component(_ts_name ${_ts_file} NAME_WE)

get_filename_component(_name ${_ts_file} NAME)
string(REGEX REPLACE "^(.+)(\\.[^.]+)$" "\\1" _ts_name ${_name})

set(_ts_lst_file "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_ts_name}_lst_file")
set(_lst_file_srcs)
foreach(_lst_file_src ${_my_sources})
set(_lst_file_srcs "${_lst_file_src}\n${_lst_file_srcs}")
endforeach()

get_directory_property(_inc_DIRS INCLUDE_DIRECTORIES)
foreach(_pro_include ${_inc_DIRS})
get_filename_component(_abs_include "${_pro_include}" ABSOLUTE)
set(_lst_file_srcs "-I${_pro_include}\n${_lst_file_srcs}")
endforeach()

file(WRITE ${_ts_lst_file} "${_lst_file_srcs}")
endif()
add_custom_command(OUTPUT ${_ts_file}
COMMAND ${Qt5_LUPDATE_EXECUTABLE}
ARGS ${_lupdate_options} "@${_ts_lst_file}" -ts ${_ts_file}
DEPENDS ${_my_sources} ${_ts_lst_file} VERBATIM)
endforeach()
qt5_patched_add_translation(${_qm_files} ${_my_tsfiles})
set(${_qm_files} ${${_qm_files}} PARENT_SCOPE)
endfunction()


function(QT5_PATCHED_ADD_TRANSLATION _qm_files)
foreach(_current_FILE ${ARGN})
get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
Expand Down