diff options
author | Julian Andres Klode <jak@debian.org> | 2016-08-07 16:01:18 +0200 |
---|---|---|
committer | Julian Andres Klode <jak@debian.org> | 2016-08-10 16:11:05 +0200 |
commit | 9a5537fcc6d3ea98909360636a45bd3cf3aba1d1 (patch) | |
tree | f0e408f948ace96798964e7bb7eaf53873f6f484 | |
parent | 6ff8727a0641b299ac32bc897d3ac1246b02061e (diff) |
CMake: Translations: Build apt-all.pot and update .po files
Merge all the per-domain templates into one template file using
msgcomm, stripping any line numbers in the input files, and sorting
the output per file.
This should create reasonably stable .pot and .po files that do not
change just because files move around. It should also be resilient
against some line changes, as long as one translated line is not
moved before/after another translated line.
Gbp-Dch: ignore
-rw-r--r-- | CMake/Translations.cmake | 46 | ||||
-rw-r--r-- | README.cmake | 1 | ||||
-rw-r--r-- | po/CMakeLists.txt | 10 |
3 files changed, 54 insertions, 3 deletions
diff --git a/CMake/Translations.cmake b/CMake/Translations.cmake index 1b9781d69..6a9862005 100644 --- a/CMake/Translations.cmake +++ b/CMake/Translations.cmake @@ -13,6 +13,13 @@ function(apt_add_translation_domain) set(abs_scripts "") set(targets ${NLS_TARGETS}) set(domain ${NLS_DOMAIN}) + set(xgettext_params + --add-comments + --foreign + --package-name=${PROJECT_NAME} + --package-version=${PACKAGE_VERSION} + --msgid-bugs-address=${PACKAGE_MAIL} + ) foreach(source ${NLS_SCRIPTS}) string(SUBSTRING ${source} 0 1 init_char) string(COMPARE EQUAL ${init_char} "/" is_absolute) @@ -50,19 +57,21 @@ function(apt_add_translation_domain) set(sh_pot ${PROJECT_BINARY_DIR}/${domain}.sh.pot) # Create the template for this specific sub-domain add_custom_command (OUTPUT ${sh_pot} - COMMAND xgettext --add-comments --foreign -L Shell + COMMAND xgettext ${xgettext_params} -L Shell -o ${sh_pot} ${scripts} DEPENDS ${abs_scripts} + VERBATIM WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} ) endif() add_custom_command (OUTPUT ${PROJECT_BINARY_DIR}/${domain}.c.pot - COMMAND xgettext --add-comments --foreign -k_ -kN_ + COMMAND xgettext ${xgettext_params} -k_ -kN_ --keyword=P_:1,2 -o ${PROJECT_BINARY_DIR}/${domain}.c.pot ${files} DEPENDS ${abs_files} + VERBATIM WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} ) @@ -100,3 +109,36 @@ function(apt_add_translation_domain) add_custom_target(nls-${domain} ALL DEPENDS ${mofiles}) endfunction() + +# Usage: apt_add_update_po(output domain [domain ...]) +function(apt_add_update_po) + set(options) + set(oneValueArgs TEMPLATE) + set(multiValueArgs DOMAINS) + cmake_parse_arguments(NLS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + set(output ${CMAKE_CURRENT_SOURCE_DIR}/${NLS_TEMPLATE}.pot) + foreach(domain ${NLS_DOMAINS}) + list(APPEND potfiles ${PROJECT_BINARY_DIR}/${domain}.pot) + endforeach() + + get_filename_component(master_name ${output} NAME_WE) + add_custom_target(nls-${master_name} + COMMAND msgcomm --sort-by-file --add-location=file + --more-than=0 --output=${output} + ${potfiles} + DEPENDS ${potfiles}) + + file(GLOB translations "${PROJECT_SOURCE_DIR}/po/*.po") + if (NOT TARGET update-po) + add_custom_target(update-po) + endif() + foreach(translation ${translations}) + get_filename_component(langcode ${translation} NAME_WE) + add_custom_target(update-po-${langcode} + COMMAND msgmerge -q --update --backup=none ${translation} ${output} + DEPENDS nls-${master_name} + ) + add_dependencies(update-po update-po-${langcode}) + endforeach() + add_dependencies(update-po nls-${master_name}) +endfunction() diff --git a/README.cmake b/README.cmake index 1a4d2a448..0ffd08efc 100644 --- a/README.cmake +++ b/README.cmake @@ -33,4 +33,3 @@ The following features have not been implemented yet: - Translated docbook guides - unit tests - - update-po diff --git a/po/CMakeLists.txt b/po/CMakeLists.txt index c7dfcb0fb..4fdac3959 100644 --- a/po/CMakeLists.txt +++ b/po/CMakeLists.txt @@ -26,3 +26,13 @@ apt_add_translation_domain( DOMAIN libapt-inst${APT_INST_MAJOR} TARGETS apt-inst ) + +apt_add_update_po( + TEMPLATE + apt-all + DOMAINS + libapt-pkg${APT_PKG_MAJOR} + libapt-inst${APT_INST_MAJOR} + apt + apt-utils +) |