]> git.saurik.com Git - apt.git/blame - CMake/Translations.cmake
CMake: Set PACKAGE_MAIL variable
[apt.git] / CMake / Translations.cmake
CommitLineData
7def2482
JAK
1# translations.cmake - Translations using APT's translation system.
2# Copyright (C) 2009, 2016 Julian Andres Klode <jak@debian.org>
3
4function(apt_add_translation_domain domain)
5 set(targets ${ARGN})
6 # Build the list of source files of the target
7 set(files "")
8 foreach(target ${targets})
9 get_target_property(source_dir ${target} SOURCE_DIR)
10 get_target_property(sources ${target} SOURCES)
11 foreach(source ${sources})
12 string(SUBSTRING ${source} 0 1 init_char)
13 string(COMPARE EQUAL ${init_char} "/" is_absolute)
14 if (${is_absolute})
15 set(file "${source}")
16 else()
17 set(file "${source_dir}/${source}")
18 endif()
19 file(RELATIVE_PATH relfile ${PROJECT_SOURCE_DIR} ${file})
20 set(files ${files} ${relfile})
21 endforeach()
22
23 target_compile_definitions(${target} PRIVATE -DAPT_DOMAIN="${domain}")
24 endforeach()
25
26 # Create the template for this specific sub-domain
27 add_custom_command (OUTPUT ${PROJECT_BINARY_DIR}/${domain}.pot
28 COMMAND xgettext --add-comments --foreign -k_ -kN_
29 -o ${PROJECT_BINARY_DIR}/${domain}.pot ${files}
30 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
31 )
32
33 # Build .mo files
34 file(GLOB translations "${PROJECT_SOURCE_DIR}/po/*.po")
35 list(SORT translations)
36 foreach(file ${translations})
37 get_filename_component(langcode ${file} NAME_WE)
38 set(outdir ${PROJECT_BINARY_DIR}/locale/${langcode}/LC_MESSAGES)
39 file(MAKE_DIRECTORY ${outdir})
40 # Command to merge and compile the messages
41 add_custom_command(OUTPUT ${outdir}/${domain}.mo
42 COMMAND msgmerge -qo - ${file} ${PROJECT_BINARY_DIR}/${domain}.pot |
43 msgfmt -o ${outdir}/${domain}.mo -
44 DEPENDS ${file} ${PROJECT_BINARY_DIR}/${domain}.pot
45 )
46
47 set(mofiles ${mofiles} ${outdir}/${domain}.mo)
48 install(FILES ${outdir}/${domain}.mo
49 DESTINATION "${CMAKE_INSTALL_LOCALEDIR}/${langcode}/LC_MESSAGES")
50 endforeach(file ${translations})
51
52 add_custom_target(nls-${domain} ALL DEPENDS ${mofiles})
53endfunction()