Translations.cmake 2.1 KB

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