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