Support translation catalogs added in KDE Application release tarball

Summary:
Starting with KDE Applications 17.04 the po files for the translations
are now added to the tarball of the sources they belong to, instead of
being released separately.
The release script also makes the assumption that all KDE Applications
use CMake, ECM and KI18n and simply inject the lines
ecm_install_po_files_as_qm(poqm)
ki18n_install(po)
to the end of the toplevel CMakeLists.txt.

Which does not work for Marble. To solve this, the release script
creating the KDE Applications tarballs gives Marble some special handling.

Additionally Marble's buildsystem needs to handle the case of Qt-only
building, where both macros are not available.

This patch solves this for now  by using a custom macro for the po->qm files,
and (in a temporary hacky way) calling ki18n_install in a subdir
where the macro is known due to linking against KI18n and which will be
skipt in qt-only builds.

For that this patch moves the existing code for handling the
po->qm translations for the bundle packaging of marble-maps into the
global MarbleMacros.cmake file and adapts it, so it can be reused also
for the release tarball po->qm files.

Test Plan:
Without po and poqm file build works as before.
Copied the po and poqm files from the released tarballs into the
toplevel dir, qm & mo files were created and installed as they should.

Custom bundle_translations target also works as before.

Reviewers: rahn, nienhueser, ltoscano, aacid

Reviewed By: nienhueser

Differential Revision: https://phabricator.kde.org/D5648
parent b1b1c263
...@@ -335,6 +335,30 @@ if(BUILD_MARBLE_EXAMPLES) ...@@ -335,6 +335,30 @@ if(BUILD_MARBLE_EXAMPLES)
add_subdirectory(examples/cpp) add_subdirectory(examples/cpp)
endif() endif()
####################################################
# Handle translation catalogs of KDE Application release tarball of marble
# (for custom bundle translation handling see data/lang/README)
# KDE Application release tarballs have the respective po files added on tarball creation,
# which are otherwise stored and edited separately on the KDE svn servers.
# Toplevel subdir "poqm/" holds all the po files which should be processed and installed as qm files
marble_install_po_files_as_qm(poqm)
# Toplevel subdir "po/" holds all the po files which should be processed and installed as mo files
# Those are used by app and plugin code building against KI18n.
# So the respective macro ki18n_install can be used.
# Just, the macro is not available here in the toplevel CMakeLists.txt file.
# As a temporary hack (your task to improve it, dear reader :) ) the macro
# is called only from src/apps/marble-kde/CMakeLists.txt.
# That should catch 99.9 % cases of builds from released tarball, where all the
# KF5-dependant apps and plugins will be built and installed together.
# Currently these are:
# src/apps/marble-kde
# src/plasmarunner
# src/plasma/applets/worldclock
# src/plasma/wallpapers/worldmap
#################################################### ####################################################
# Install extra files # Install extra files
install(FILES LICENSE.txt DESTINATION ${MARBLE_DATA_INSTALL_PATH}) install(FILES LICENSE.txt DESTINATION ${MARBLE_DATA_INSTALL_PATH})
......
...@@ -147,3 +147,119 @@ macro(ADD_FEATURE_INFO) ...@@ -147,3 +147,119 @@ macro(ADD_FEATURE_INFO)
# just ignore it # just ignore it
endmacro() endmacro()
endif() endif()
# Find Qt translation tools
find_package(Qt5LinguistTools CONFIG)
if(NOT Qt5LinguistTools_FOUND)
# dummy implementation
function(marble_install_po_files_as_qm podir)
set(options)
set(oneValueArgs TARGET)
set(multiValueArgs)
cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(ARGS_TARGET)
if(NOT TARGET ${ARGS_TARGET})
add_custom_target(${ARGS_TARGET})
endif()
endif()
if (NOT IS_ABSOLUTE "${podir}")
set(podir "${CMAKE_CURRENT_SOURCE_DIR}/${podir}")
endif()
if (IS_DIRECTORY "${podir}")
message(STATUS "Will do nothing for po files in \"${podir}\", tools missing")
endif()
endfunction()
else()
if(TARGET Qt5::lconvert)
set(lconvert_executable Qt5::lconvert)
else()
# Qt < 5.3.1 does not define Qt5::lconvert
get_target_property(lrelease_location Qt5::lrelease LOCATION)
get_filename_component(lrelease_path ${lrelease_location} PATH)
find_program(lconvert_executable
NAMES lconvert-qt5 lconvert
PATHS ${lrelease_path}
NO_DEFAULT_PATH
)
endif()
function(marble_process_po_files_as_qm lang po_file)
set(options)
set(oneValueArgs TARGET)
set(multiValueArgs)
cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
# Create commands to turn po files into qm files
get_filename_component(po_file ${po_file} ABSOLUTE)
get_filename_component(filename_base ${po_file} NAME_WE)
# Include ${lang} in build dir because we might be called multiple times
# with the same ${filename_base}
set(build_dir ${CMAKE_CURRENT_BINARY_DIR}/locale/${lang})
set(ts_file ${build_dir}/${filename_base}.ts)
set(qm_file ${build_dir}/${filename_base}.qm)
file(MAKE_DIRECTORY ${build_dir})
# lconvert from .po to .ts, then lrelease from .ts to .qm.
add_custom_command(OUTPUT ${qm_file}
COMMAND ${lconvert_executable}
ARGS -i ${po_file} -o ${ts_file} -target-language ${lang}
COMMAND Qt5::lrelease
ARGS -removeidentical -nounfinished -silent ${ts_file} -qm ${qm_file}
DEPENDS ${po_file}
)
install(
FILES ${qm_file}
DESTINATION ${data_dir}/locale/${lang}
OPTIONAL # if not build, ignore it
)
if(ARGS_TARGET)
set(target_name_prefix ${ARGS_TARGET})
else()
set(target_name_prefix translation)
endif()
string(REPLACE "@" "AT" _lang ${lang})
set(target_name ${target_name_prefix}_${_lang}_${filename_base})
if(ARGS_TARGET)
add_custom_target(${target_name} DEPENDS ${qm_file})
add_dependencies(${ARGS_TARGET} ${target_name})
else()
add_custom_target(${target_name} ALL DEPENDS ${qm_file})
endif()
endfunction()
function(marble_install_po_files_as_qm podir)
set(options)
set(oneValueArgs TARGET)
set(multiValueArgs)
cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(ARGS_TARGET)
if(NOT TARGET ${ARGS_TARGET})
add_custom_target(${ARGS_TARGET})
endif()
set(target_arg TARGET ${ARGS_TARGET})
else()
set(target_arg)
endif()
file(GLOB po_files "${podir}/*/*.po")
foreach(po_file ${po_files})
get_filename_component(po_dir ${po_file} DIRECTORY)
get_filename_component(lang ${po_dir} NAME)
marble_process_po_files_as_qm(${lang} ${po_file} ${target_arg})
endforeach()
endfunction()
endif()
# custom translation catalog , for creation of bundled binary packages # custom translation catalog , for creation of bundled binary packages
# TODO: disable for builds in normal linux distri builds, to not confuse people # TODO: disable for builds in normal linux distri builds, to not confuse people
marble_install_po_files_as_qm(po TARGET bundle_translations)
# Find Qt translation tools
find_package(Qt5LinguistTools CONFIG)
# enable target in any case
add_custom_target(bundle_translations)
if(NOT Qt5LinguistTools_FOUND)
return()
endif()
if(TARGET Qt5::lconvert)
set(lconvert_executable Qt5::lconvert)
else()
# Qt < 5.3.1 does not define Qt5::lconvert
get_target_property(lrelease_location Qt5::lrelease LOCATION)
get_filename_component(lrelease_path ${lrelease_location} PATH)
find_program(lconvert_executable
NAMES lconvert-qt5 lconvert
PATHS ${lrelease_path}
NO_DEFAULT_PATH
)
endif()
function(marble_process_po_files_as_qm lang po_file)
# Create commands to turn po files into qm files
get_filename_component(po_file ${po_file} ABSOLUTE)
get_filename_component(filename_base ${po_file} NAME_WE)
# Include ${lang} in build dir because we might be called multiple times
# with the same ${filename_base}
set(build_dir ${CMAKE_CURRENT_BINARY_DIR}/locale/${lang})
set(ts_file ${build_dir}/${filename_base}.ts)
set(qm_file ${build_dir}/${filename_base}.qm)
file(MAKE_DIRECTORY ${build_dir})
# lconvert from .po to .ts, then lrelease from .ts to .qm.
add_custom_command(OUTPUT ${qm_file}
COMMAND ${lconvert_executable}
ARGS -i ${po_file} -o ${ts_file} -target-language ${lang}
COMMAND Qt5::lrelease
ARGS -removeidentical -nounfinished -silent ${ts_file} -qm ${qm_file}
DEPENDS ${po_file}
)
install(
FILES ${qm_file}
DESTINATION ${data_dir}/locale/${lang}
OPTIONAL # if not build, ignore it
)
string(REPLACE "@" "AT" _lang ${lang})
set(target_name translation_${_lang}_${filename_base})
add_custom_target(${target_name} DEPENDS ${qm_file})
add_dependencies(bundle_translations ${target_name})
endfunction()
file(GLOB po_files "po/*/*.po")
foreach(po_file ${po_files})
get_filename_component(po_dir ${po_file} DIRECTORY)
get_filename_component(lang ${po_dir} NAME)
marble_process_po_files_as_qm(${lang} ${po_file})
endforeach()
...@@ -80,3 +80,7 @@ install(FILES marble.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR}) ...@@ -80,3 +80,7 @@ install(FILES marble.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
# register marble app as schemehandler # register marble app as schemehandler
install(FILES marble_geo.desktop DESTINATION ${KDE_INSTALL_APPDIR}) install(FILES marble_geo.desktop DESTINATION ${KDE_INSTALL_APPDIR})
install(FILES marble_worldwind.desktop DESTINATION ${KDE_INSTALL_APPDIR}) install(FILES marble_worldwind.desktop DESTINATION ${KDE_INSTALL_APPDIR})
# Handle mo-targetted translation catalogs as added for release tarballs
# see toplevel CMakeLists.txt for further explanation why it is done here
ki18n_install(${CMAKE_SOURCE_DIR}/po)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment