summaryrefslogtreecommitdiff
path: root/CMake
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2016-08-07 16:01:18 +0200
committerJulian Andres Klode <jak@debian.org>2016-08-10 16:11:05 +0200
commit9a5537fcc6d3ea98909360636a45bd3cf3aba1d1 (patch)
treef0e408f948ace96798964e7bb7eaf53873f6f484 /CMake
parent6ff8727a0641b299ac32bc897d3ac1246b02061e (diff)
downloadapt-9a5537fcc6d3ea98909360636a45bd3cf3aba1d1.tar.gz
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
Diffstat (limited to 'CMake')
-rw-r--r--CMake/Translations.cmake46
1 files changed, 44 insertions, 2 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()