diff options
author | Julian Andres Klode <jak@debian.org> | 2016-08-06 21:11:06 +0200 |
---|---|---|
committer | Julian Andres Klode <jak@debian.org> | 2016-08-06 22:36:02 +0200 |
commit | 7def24826c298df77e34fd17bb72c570a22b04bd (patch) | |
tree | 7b97d2acd914e4543c3388f061eb3ed0ee294b42 /CMake | |
parent | f3de2dbaf657f9040a4da448c57267de0fef7d33 (diff) | |
download | apt-7def24826c298df77e34fd17bb72c570a22b04bd.tar.gz |
CMake: Add support for building and installing .mo files
Introduce support for building translation domain-specific
templates, merging them with the translations, and building
a language-specific .mo file.
The invocation of xgettext is done in the project source
directory, not in the current source directory, and all paths
are made relative to the project root, in order to have clean
templates.
This only supports the C++ source code for now, it unfortunately
does not handle the shell scripts of deselect yet.
Diffstat (limited to 'CMake')
-rw-r--r-- | CMake/Translations.cmake | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/CMake/Translations.cmake b/CMake/Translations.cmake new file mode 100644 index 000000000..2a1e03d4c --- /dev/null +++ b/CMake/Translations.cmake @@ -0,0 +1,53 @@ +# 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}) + # Build the list of source files of the target + set(files "") + foreach(target ${targets}) + get_target_property(source_dir ${target} SOURCE_DIR) + get_target_property(sources ${target} SOURCES) + foreach(source ${sources}) + string(SUBSTRING ${source} 0 1 init_char) + string(COMPARE EQUAL ${init_char} "/" is_absolute) + if (${is_absolute}) + set(file "${source}") + else() + set(file "${source_dir}/${source}") + endif() + file(RELATIVE_PATH relfile ${PROJECT_SOURCE_DIR} ${file}) + set(files ${files} ${relfile}) + endforeach() + + 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 + COMMAND xgettext --add-comments --foreign -k_ -kN_ + -o ${PROJECT_BINARY_DIR}/${domain}.pot ${files} + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + ) + + # Build .mo files + file(GLOB translations "${PROJECT_SOURCE_DIR}/po/*.po") + list(SORT translations) + foreach(file ${translations}) + get_filename_component(langcode ${file} NAME_WE) + set(outdir ${PROJECT_BINARY_DIR}/locale/${langcode}/LC_MESSAGES) + file(MAKE_DIRECTORY ${outdir}) + # Command to merge and compile the messages + add_custom_command(OUTPUT ${outdir}/${domain}.mo + COMMAND msgmerge -qo - ${file} ${PROJECT_BINARY_DIR}/${domain}.pot | + msgfmt -o ${outdir}/${domain}.mo - + DEPENDS ${file} ${PROJECT_BINARY_DIR}/${domain}.pot + ) + + set(mofiles ${mofiles} ${outdir}/${domain}.mo) + install(FILES ${outdir}/${domain}.mo + DESTINATION "${CMAKE_INSTALL_LOCALEDIR}/${langcode}/LC_MESSAGES") + endforeach(file ${translations}) + + add_custom_target(nls-${domain} ALL DEPENDS ${mofiles}) +endfunction() |