i18n: Shuffle the build so that all the bits are in lang/

Move the CMake code responsible for building the translations from
the src/calamares directory (yeah, yeah, the translations need to
link into the executable) into lang/ (which is where the source
and other infrastructure lives).
This commit is contained in:
Adriaan de Groot 2021-09-07 16:31:24 +02:00
parent 06d12fc924
commit 438302fcf5
3 changed files with 53 additions and 35 deletions

View File

@ -404,7 +404,10 @@ set(Calamares_WITH_QML ${WITH_QML})
### Transifex Translation status
#
# Construct language lists for use.
# Construct language lists for use. This massages the language lists
# for use with older Qt (which does not support Esperanto) and checks
# for some obvious error. The actual work of compiling translations
# is done in the lang/ directory.
#
if( Qt5_VERSION VERSION_GREATER 5.12.1 )
# At least Qt 5.12.2 seems to support Esperanto in QLocale

View File

@ -4,6 +4,14 @@
# SPDX-License-Identifier: BSD-2-Clause
#
###
#
# This CMakeList handles the following i18n / language targets:
#
# - creating a translation test-tool
# - building the Python (gettext-based) translations
# - compiling all the Qt translations into a C++ file calamares-i18n.cxx
# - defines an OBJECT LIBRARY calamares-i18n for linking the compiled
# translations into an executable.
include( CalamaresAddTranslations )
@ -18,3 +26,39 @@ install_calamares_gettext_translations( python
FILENAME python.mo
RENAME calamares-python.mo
)
### TRANSLATIONS
#
#
set( TS_FILES "" )
set( calamares_i18n_qrc_content "" )
# 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 )
qt5_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})

View File

@ -34,45 +34,15 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
)
### TRANSLATIONS
#
#
set( TS_FILES "" )
set( calamares_i18n_qrc_content "" )
# 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" )
set( calamares_i18n_qrc_content "${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}/qrc_${trans_file}.cxx )
configure_file( ${CMAKE_SOURCE_DIR}/lang/calamares_i18n.qrc.in ${trans_infile} @ONLY )
qt5_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}
)
### EXECUTABLE
#
# "calamares_bin" is the main application, not to be confused with
# the target "calamares" which is the non-GUI library part.
#
add_executable( calamares_bin ${calamaresSources} calamares.qrc ${trans_outfile} )
# The calamares-i18n.cxx file -- full path in CALAMARES_TRANSLATIONS_SOURCE --
# is created as a target in the lang/ directory. This is compiled to a
# library (it's just the result of a QRC compile).
add_executable( calamares_bin ${calamaresSources} calamares.qrc )
target_include_directories( calamares_bin PRIVATE ${CMAKE_SOURCE_DIR} )
set_target_properties(calamares_bin
PROPERTIES
@ -91,6 +61,7 @@ target_link_libraries( calamares_bin
PRIVATE
calamares
calamaresui
calamares-i18n
Qt5::Core
Qt5::Widgets
KF5::CoreAddons