diff options
author | Julian Andres Klode <jak@debian.org> | 2016-08-07 15:52:59 +0200 |
---|---|---|
committer | Julian Andres Klode <jak@debian.org> | 2016-08-10 16:11:05 +0200 |
commit | 6ff8727a0641b299ac32bc897d3ac1246b02061e (patch) | |
tree | 2acddb42e56ed5a70f4eb0b0bce0ff6ba30b3736 /CMake/Translations.cmake | |
parent | a331fb701683779d4113c39243f39ffad28cb912 (diff) |
CMake: Translations: Add support for shell scripts
Rework the arguments to apt_add_translation_domain so a user
can specify TARGETS and SCRIPTS, the latter being Shell scripts.
For each language (TARGETS being C++, SCRIPTS being Shell), a separate
template is generated via xgettext. Those templates are then merged
together by using msgcomm. In case there are no Shell scripts in
the translation domain, msgcomm will receive /dev/null instead of
a shell translation template.
This also reintroduces line numbers, as msgcomm would otherwise
re-order the merged files not only by filename, but also by message
string. It's unclear why it does that, it could just leave strings
within a file alone.
In contrast to the old build system, we use xgettext for shell scripts
instead of bash --dump-strings, as it's just easier to use the same
tool for everything. We also create valid headers.
Diffstat (limited to 'CMake/Translations.cmake')
-rw-r--r-- | CMake/Translations.cmake | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/CMake/Translations.cmake b/CMake/Translations.cmake index a26bf1c17..1b9781d69 100644 --- a/CMake/Translations.cmake +++ b/CMake/Translations.cmake @@ -1,11 +1,30 @@ # translations.cmake - Translations using APT's translation system. # Copyright (C) 2009, 2016 Julian Andres Klode <jak@debian.org> -function(apt_add_translation_domain domain) - set(targets ${ARGN}) +function(apt_add_translation_domain) + set(options) + set(oneValueArgs DOMAIN) + set(multiValueArgs TARGETS SCRIPTS) + cmake_parse_arguments(NLS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) # Build the list of source files of the target set(files "") set(abs_files "") + set(scripts "") + set(abs_scripts "") + set(targets ${NLS_TARGETS}) + set(domain ${NLS_DOMAIN}) + foreach(source ${NLS_SCRIPTS}) + string(SUBSTRING ${source} 0 1 init_char) + string(COMPARE EQUAL ${init_char} "/" is_absolute) + if (${is_absolute}) + set(file "${source}") + else() + set(file "${CMAKE_CURRENT_SOURCE_DIR}/${source}") + endif() + file(RELATIVE_PATH relfile ${PROJECT_SOURCE_DIR} ${file}) + list(APPEND scripts ${relfile}) + list(APPEND abs_scripts ${file}) + endforeach() foreach(target ${targets}) get_target_property(source_dir ${target} SOURCE_DIR) get_target_property(sources ${target} SOURCES) @@ -25,15 +44,38 @@ function(apt_add_translation_domain domain) target_compile_definitions(${target} PRIVATE -DAPT_DOMAIN="${domain}") endforeach() - # Create the template for this specific sub-domain - add_custom_command (OUTPUT ${PROJECT_BINARY_DIR}/${domain}.pot + if("${scripts}" STREQUAL "") + set(sh_pot "/dev/null") + else() + 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 + -o ${sh_pot} ${scripts} + DEPENDS ${abs_scripts} + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + ) + endif() + + + add_custom_command (OUTPUT ${PROJECT_BINARY_DIR}/${domain}.c.pot COMMAND xgettext --add-comments --foreign -k_ -kN_ - --add-location=file --keyword=P_:1,2 - -o ${PROJECT_BINARY_DIR}/${domain}.pot ${files} + --keyword=P_:1,2 + -o ${PROJECT_BINARY_DIR}/${domain}.c.pot ${files} DEPENDS ${abs_files} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} ) + add_custom_command (OUTPUT ${PROJECT_BINARY_DIR}/${domain}.pot + COMMAND msgcomm --more-than=0 --sort-by-file + ${sh_pot} + ${PROJECT_BINARY_DIR}/${domain}.c.pot + --output=${PROJECT_BINARY_DIR}/${domain}.pot + DEPENDS ${sh_pot} + ${PROJECT_BINARY_DIR}/${domain}.c.pot + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + ) + # Build .mo files file(GLOB translations "${PROJECT_SOURCE_DIR}/po/*.po") list(SORT translations) |