1 # translations.cmake - Translations using APT's translation system.
2 # Copyright (C) 2009, 2016 Julian Andres Klode <jak@debian.org>
4 function(apt_add_translation_domain domain)
6 # Build the list of source files of the target
9 foreach(target ${targets})
10 get_target_property(source_dir ${target} SOURCE_DIR)
11 get_target_property(sources ${target} SOURCES)
12 foreach(source ${sources})
13 string(SUBSTRING ${source} 0 1 init_char)
14 string(COMPARE EQUAL ${init_char} "/" is_absolute)
18 set(file "${source_dir}/${source}")
20 file(RELATIVE_PATH relfile ${PROJECT_SOURCE_DIR} ${file})
21 set(files ${files} ${relfile})
22 set(abs_files ${abs_files} ${file})
25 target_compile_definitions(${target} PRIVATE -DAPT_DOMAIN="${domain}")
28 # Create the template for this specific sub-domain
29 add_custom_command (OUTPUT ${PROJECT_BINARY_DIR}/${domain}.pot
30 COMMAND xgettext --add-comments --foreign -k_ -kN_
31 --add-location=file --keyword=P_:1,2
32 -o ${PROJECT_BINARY_DIR}/${domain}.pot ${files}
34 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
38 file(GLOB translations "${PROJECT_SOURCE_DIR}/po/*.po")
39 list(SORT translations)
40 foreach(file ${translations})
41 get_filename_component(langcode ${file} NAME_WE)
42 set(outdir ${PROJECT_BINARY_DIR}/locale/${langcode}/LC_MESSAGES)
43 file(MAKE_DIRECTORY ${outdir})
44 # Command to merge and compile the messages
45 add_custom_command(OUTPUT ${outdir}/${domain}.mo
46 COMMAND msgmerge -qo - ${file} ${PROJECT_BINARY_DIR}/${domain}.pot |
47 msgfmt --statistics -o ${outdir}/${domain}.mo -
48 DEPENDS ${file} ${PROJECT_BINARY_DIR}/${domain}.pot
51 set(mofiles ${mofiles} ${outdir}/${domain}.mo)
52 install(FILES ${outdir}/${domain}.mo
53 DESTINATION "${CMAKE_INSTALL_LOCALEDIR}/${langcode}/LC_MESSAGES")
54 endforeach(file ${translations})
56 add_custom_target(nls-${domain} ALL DEPENDS ${mofiles})