]> git.saurik.com Git - apt.git/blame - CMake/Translations.cmake
Add statvfs.h.in to CMake directory
[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
6ff8727a
JAK
4function(apt_add_translation_domain)
5 set(options)
6 set(oneValueArgs DOMAIN)
32a32d75 7 set(multiValueArgs TARGETS SCRIPTS EXCLUDE_LANGUAGES)
6ff8727a 8 cmake_parse_arguments(NLS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
7def2482
JAK
9 # Build the list of source files of the target
10 set(files "")
ba69ce6d 11 set(abs_files "")
6ff8727a
JAK
12 set(scripts "")
13 set(abs_scripts "")
14 set(targets ${NLS_TARGETS})
15 set(domain ${NLS_DOMAIN})
9a5537fc
JAK
16 set(xgettext_params
17 --add-comments
18 --foreign
19 --package-name=${PROJECT_NAME}
20 --package-version=${PACKAGE_VERSION}
21 --msgid-bugs-address=${PACKAGE_MAIL}
22 )
6ff8727a 23 foreach(source ${NLS_SCRIPTS})
0d04a498 24 path_join(file "${CMAKE_CURRENT_SOURCE_DIR}" "${source}")
6ff8727a
JAK
25 file(RELATIVE_PATH relfile ${PROJECT_SOURCE_DIR} ${file})
26 list(APPEND scripts ${relfile})
27 list(APPEND abs_scripts ${file})
28 endforeach()
7def2482
JAK
29 foreach(target ${targets})
30 get_target_property(source_dir ${target} SOURCE_DIR)
31 get_target_property(sources ${target} SOURCES)
32 foreach(source ${sources})
0d04a498 33 path_join(file "${source_dir}" "${source}")
7def2482
JAK
34 file(RELATIVE_PATH relfile ${PROJECT_SOURCE_DIR} ${file})
35 set(files ${files} ${relfile})
ba69ce6d 36 set(abs_files ${abs_files} ${file})
7def2482
JAK
37 endforeach()
38
39 target_compile_definitions(${target} PRIVATE -DAPT_DOMAIN="${domain}")
40 endforeach()
41
6ff8727a
JAK
42 if("${scripts}" STREQUAL "")
43 set(sh_pot "/dev/null")
44 else()
173fa882 45 set(sh_pot ${CMAKE_CURRENT_BINARY_DIR}/${domain}.sh.pot)
6ff8727a
JAK
46 # Create the template for this specific sub-domain
47 add_custom_command (OUTPUT ${sh_pot}
9a5537fc 48 COMMAND xgettext ${xgettext_params} -L Shell
6ff8727a
JAK
49 -o ${sh_pot} ${scripts}
50 DEPENDS ${abs_scripts}
9a5537fc 51 VERBATIM
6ff8727a
JAK
52 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
53 )
54 endif()
55
56
173fa882 57 add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${domain}.c.pot
9a5537fc 58 COMMAND xgettext ${xgettext_params} -k_ -kN_
6ff8727a 59 --keyword=P_:1,2
173fa882 60 -o ${CMAKE_CURRENT_BINARY_DIR}/${domain}.c.pot ${files}
ba69ce6d 61 DEPENDS ${abs_files}
9a5537fc 62 VERBATIM
7def2482
JAK
63 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
64 )
65
e164341c
JAK
66 # We are building a ${domain}.pot with a header for launchpad, but we also
67 # build a ${domain.pot}-tmp as a byproduct. The msgfmt command than depend
68 # on the byproduct while their target depends on the output, so that msgfmt
69 # does not have to be rerun if nothing in the template changed.
173fa882
JAK
70 add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot
71 BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot-tmp
6ff8727a
JAK
72 COMMAND msgcomm --more-than=0 --sort-by-file
73 ${sh_pot}
173fa882
JAK
74 ${CMAKE_CURRENT_BINARY_DIR}/${domain}.c.pot
75 --output=${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot
e164341c
JAK
76 COMMAND msgcomm --more-than=0 --omit-header --sort-by-file
77 ${sh_pot}
173fa882
JAK
78 ${CMAKE_CURRENT_BINARY_DIR}/${domain}.c.pot
79 --output=${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot-tmp0
e164341c 80 COMMAND cmake -E copy_if_different
173fa882
JAK
81 ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot-tmp0
82 ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot-tmp
6ff8727a 83 DEPENDS ${sh_pot}
173fa882 84 ${CMAKE_CURRENT_BINARY_DIR}/${domain}.c.pot
6ff8727a
JAK
85 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
86 )
87
e164341c
JAK
88 # We need a target to depend on otherwise, the msgmerge might not get called
89 # with the make generator
173fa882 90 add_custom_target(nls-${domain}-template DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot)
e164341c 91
7def2482
JAK
92 # Build .mo files
93 file(GLOB translations "${PROJECT_SOURCE_DIR}/po/*.po")
94 list(SORT translations)
95 foreach(file ${translations})
96 get_filename_component(langcode ${file} NAME_WE)
32a32d75
JAK
97 if ("${langcode}" IN_LIST NLS_EXCLUDE_LANGUAGES)
98 continue()
99 endif()
173fa882 100 set(outdir ${CMAKE_CURRENT_BINARY_DIR}/locale/${langcode}/LC_MESSAGES)
7def2482 101 file(MAKE_DIRECTORY ${outdir})
e164341c
JAK
102 # Command to merge and compile the messages. As explained in the custom
103 # command for msgcomm, this depends on byproduct to avoid reruns
a331fb70 104 add_custom_command(OUTPUT ${outdir}/${domain}.po
173fa882
JAK
105 COMMAND msgmerge -qo ${outdir}/${domain}.po ${file} ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot-tmp
106 DEPENDS ${file} ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot-tmp
7def2482 107 )
a331fb70
JAK
108 add_custom_command(OUTPUT ${outdir}/${domain}.mo
109 COMMAND msgfmt --statistics -o ${outdir}/${domain}.mo ${outdir}/${domain}.po
110 DEPENDS ${outdir}/${domain}.po
111 )
7def2482
JAK
112
113 set(mofiles ${mofiles} ${outdir}/${domain}.mo)
114 install(FILES ${outdir}/${domain}.mo
115 DESTINATION "${CMAKE_INSTALL_LOCALEDIR}/${langcode}/LC_MESSAGES")
116 endforeach(file ${translations})
117
e164341c 118 add_custom_target(nls-${domain} ALL DEPENDS ${mofiles} nls-${domain}-template)
7def2482 119endfunction()
9a5537fc
JAK
120
121# Usage: apt_add_update_po(output domain [domain ...])
122function(apt_add_update_po)
123 set(options)
124 set(oneValueArgs TEMPLATE)
32a32d75 125 set(multiValueArgs DOMAINS EXCLUDE_LANGUAGES)
9a5537fc
JAK
126 cmake_parse_arguments(NLS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
127 set(output ${CMAKE_CURRENT_SOURCE_DIR}/${NLS_TEMPLATE}.pot)
128 foreach(domain ${NLS_DOMAINS})
173fa882 129 list(APPEND potfiles ${CMAKE_CURRENT_BINARY_DIR}/${domain}.pot)
9a5537fc
JAK
130 endforeach()
131
132 get_filename_component(master_name ${output} NAME_WE)
133 add_custom_target(nls-${master_name}
134 COMMAND msgcomm --sort-by-file --add-location=file
135 --more-than=0 --output=${output}
136 ${potfiles}
137 DEPENDS ${potfiles})
138
139 file(GLOB translations "${PROJECT_SOURCE_DIR}/po/*.po")
140 if (NOT TARGET update-po)
141 add_custom_target(update-po)
142 endif()
143 foreach(translation ${translations})
144 get_filename_component(langcode ${translation} NAME_WE)
32a32d75
JAK
145 if ("${langcode}" IN_LIST NLS_EXCLUDE_LANGUAGES)
146 continue()
147 endif()
9a5537fc
JAK
148 add_custom_target(update-po-${langcode}
149 COMMAND msgmerge -q --update --backup=none ${translation} ${output}
150 DEPENDS nls-${master_name}
151 )
152 add_dependencies(update-po update-po-${langcode})
153 endforeach()
154 add_dependencies(update-po nls-${master_name})
155endfunction()
ddf40a42 156
32a32d75 157function(apt_add_po_statistics excluded)
ddf40a42
JAK
158 add_custom_target(statistics)
159 file(GLOB translations "${PROJECT_SOURCE_DIR}/po/*.po")
160 foreach(translation ${translations})
161 get_filename_component(langcode ${translation} NAME_WE)
32a32d75
JAK
162 if ("${langcode}" IN_LIST excluded)
163 add_custom_command(
164 TARGET statistics PRE_BUILD
165 COMMAND printf "%-6s " "${langcode}:"
166 COMMAND echo "ignored"
167 VERBATIM
168 )
169 continue()
170 endif()
ddf40a42
JAK
171 add_custom_command(
172 TARGET statistics PRE_BUILD
32a32d75 173 COMMAND printf "%-6s " "${langcode}:"
ddf40a42
JAK
174 COMMAND msgfmt --statistics -o /dev/null ${translation}
175 VERBATIM
176 )
177 endforeach()
178endfunction()