i18n: expand helper function to handle more cases
- move template QRC file to the module that defines the function - add parameters to accept more files (prefixes) per language
This commit is contained in:
parent
ca9006a1bc
commit
3173a8ee3c
@ -101,15 +101,24 @@ function( install_calamares_gettext_translations )
|
|||||||
endforeach()
|
endforeach()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
set(_calamares_qrc_translations_qrc_source ${CMAKE_CURRENT_LIST_DIR}/i18n.qrc.in) # Needs to be set outside of function
|
||||||
function(calamares_qrc_translations basename)
|
function(calamares_qrc_translations basename)
|
||||||
set(NAME ${ARGV0})
|
|
||||||
set(options "")
|
set(options "")
|
||||||
set(oneValueArgs SUBDIRECTORY OUTPUT_VARIABLE)
|
set(oneValueArgs SUBDIRECTORY OUTPUT_VARIABLE)
|
||||||
set(multiValueArgs LANGUAGES)
|
set(multiValueArgs PREFIXES LANGUAGES)
|
||||||
cmake_parse_arguments(_qrt "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
cmake_parse_arguments(_qrt "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||||
|
|
||||||
if(NOT _qrt_OUTPUT_VARIABLE)
|
if(NOT _qrt_OUTPUT_VARIABLE)
|
||||||
set(_qrt_OUTPUT_VARIABLE "qrc_translations_${basename}")
|
message(FATAL_ERROR "No output variable")
|
||||||
|
endif()
|
||||||
|
if(NOT _qrt_PREFIXES)
|
||||||
|
set(_qrt_PREFIXES "${basename}")
|
||||||
|
endif()
|
||||||
|
if(NOT _qrt_LANGUAGES)
|
||||||
|
set(_qrt_LANGUAGES ${CALAMARES_TRANSLATION_LANGUAGES})
|
||||||
|
endif()
|
||||||
|
if(NOT _qrt_SUBDIRECTORY)
|
||||||
|
set(_qrt_SUBDIRECTORY "")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(translations_qrc_infile ${CMAKE_CURRENT_BINARY_DIR}/${basename}.qrc)
|
set(translations_qrc_infile ${CMAKE_CURRENT_BINARY_DIR}/${basename}.qrc)
|
||||||
@ -119,35 +128,30 @@ function(calamares_qrc_translations basename)
|
|||||||
set(calamares_i18n_qrc_content "")
|
set(calamares_i18n_qrc_content "")
|
||||||
set(calamares_i18n_ts_filelist "")
|
set(calamares_i18n_ts_filelist "")
|
||||||
foreach(lang ${_qrt_LANGUAGES})
|
foreach(lang ${_qrt_LANGUAGES})
|
||||||
string(APPEND calamares_i18n_qrc_content "<file>${basename}_${lang}.qm</file>")
|
foreach(tlsource ${_qrt_PREFIXES})
|
||||||
list(
|
if(EXISTS "${CMAKE_SOURCE_DIR}/{$_qrt_SUBDIRECTORY}/${tlsource}_${lang}.ts")
|
||||||
APPEND
|
string(APPEND calamares_i18n_qrc_content "<file>${tlsource}_${lang}.qm</file>\n")
|
||||||
calamares_i18n_ts_filelist
|
list(APPEND calamares_i18n_ts_filelist "${CMAKE_SOURCE_DIR}/${_qrt_SUBDIRECTORY}/${tlsource}_${lang}.ts")
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/${_qrt_SUBDIRECTORY}/${basename}_${lang}.ts"
|
endif()
|
||||||
)
|
endforeach()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
configure_file(${CMAKE_SOURCE_DIR}/lang/calamares_i18n.qrc.in ${translations_qrc_infile} @ONLY)
|
configure_file(${_calamares_qrc_translations_qrc_source} ${translations_qrc_infile} @ONLY)
|
||||||
qt_add_translation(QM_FILES ${calamares_i18n_ts_filelist})
|
qt_add_translation(QM_FILES ${calamares_i18n_ts_filelist})
|
||||||
|
|
||||||
if(WITH_QT6)
|
# Run the resource compiler (rcc_options should already be set)
|
||||||
# Simplified build, knows about RCC
|
add_custom_command(
|
||||||
set(${_qrt_OUTPUT_VARIABLE} ${translations_qrc_infile} PARENT_SCOPE)
|
OUTPUT ${translations_qrc_outfile}
|
||||||
else()
|
COMMAND ${qtname}::rcc
|
||||||
# Run the resource compiler (rcc_options should already be set)
|
ARGS
|
||||||
add_custom_command(
|
${rcc_options}
|
||||||
OUTPUT ${translations_qrc_outfile}
|
--format-version 1
|
||||||
COMMAND "${Qt5Core_RCC_EXECUTABLE}"
|
-name ${basename}
|
||||||
ARGS
|
-o ${translations_qrc_outfile}
|
||||||
${rcc_options}
|
${translations_qrc_infile}
|
||||||
--format-version 1
|
MAIN_DEPENDENCY ${translations_qrc_infile}
|
||||||
-name ${basename}
|
DEPENDS ${QM_FILES}
|
||||||
-o ${translations_qrc_outfile}
|
)
|
||||||
${translations_qrc_infile}
|
|
||||||
MAIN_DEPENDENCY ${translations_qrc_infile}
|
|
||||||
DEPENDS ${QM_FILES}
|
|
||||||
)
|
|
||||||
|
|
||||||
set(${_qrt_OUTPUT_VARIABLE} ${translations_qrc_outfile} PARENT_SCOPE)
|
set(${_qrt_OUTPUT_VARIABLE} ${translations_qrc_outfile} PARENT_SCOPE)
|
||||||
endif()
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
@ -30,35 +30,9 @@ install_calamares_gettext_translations(python
|
|||||||
### TRANSLATIONS
|
### TRANSLATIONS
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
set(TS_FILES "")
|
calamares_qrc_translations(calamares-i18n
|
||||||
set(calamares_i18n_qrc_content "")
|
OUTPUT_VARIABLE translation_outfile
|
||||||
|
PREFIXES calamares tz kb
|
||||||
# calamares and qt language files
|
|
||||||
foreach(lang ${CALAMARES_TRANSLATION_LANGUAGES})
|
|
||||||
foreach(tlsource "calamares_${lang}" "tz_${lang}" "kb_${lang}")
|
|
||||||
if(EXISTS "${CMAKE_SOURCE_DIR}/lang/${tlsource}.ts")
|
|
||||||
string(APPEND calamares_i18n_qrc_content "<file>${tlsource}.qm</file>\n")
|
|
||||||
list(APPEND TS_FILES "${CMAKE_SOURCE_DIR}/lang/${tlsource}.ts")
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
set(trans_file calamares_i18n)
|
|
||||||
set(trans_infile ${CMAKE_CURRENT_BINARY_DIR}/${trans_file}.qrc)
|
|
||||||
set(trans_outfile ${CMAKE_CURRENT_BINARY_DIR}/calamares-i18n.cxx)
|
|
||||||
set(CALAMARES_TRANSLATIONS_SOURCE ${trans_outfile})
|
|
||||||
|
|
||||||
configure_file(${CMAKE_SOURCE_DIR}/lang/calamares_i18n.qrc.in ${trans_infile} @ONLY)
|
|
||||||
|
|
||||||
qt_add_translation(QM_FILES ${TS_FILES})
|
|
||||||
|
|
||||||
# Run the resource compiler (rcc_options should already be set)
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT ${trans_outfile}
|
|
||||||
COMMAND "${Qt5Core_RCC_EXECUTABLE}"
|
|
||||||
ARGS ${rcc_options} --format-version 1 -name ${trans_file} -o ${trans_outfile} ${trans_infile}
|
|
||||||
MAIN_DEPENDENCY ${trans_infile}
|
|
||||||
DEPENDS ${QM_FILES}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(calamares-i18n OBJECT ${trans_outfile})
|
add_library(calamares-i18n OBJECT ${translation_outfile})
|
||||||
|
Loading…
Reference in New Issue
Block a user