# Translations (gettext). Source strings are English; add a language by adding .po and # listing it in LINGUAS. include(GNUInstallDirs) find_package(Gettext) if(NOT GETTEXT_FOUND) message(WARNING "gettext (msgfmt) not found: translations are not built") return() endif() file(STRINGS LINGUAS OPENPU_LINGUAS REGEX "^[^#]") foreach(lang IN LISTS OPENPU_LINGUAS) set(mo ${CMAKE_BINARY_DIR}/locale/${lang}/LC_MESSAGES/openpu.mo) add_custom_command(OUTPUT ${mo} COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/locale/${lang}/LC_MESSAGES COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} --check -o ${mo} ${CMAKE_CURRENT_SOURCE_DIR}/${lang}.po DEPENDS ${lang}.po) list(APPEND OPENPU_MO_FILES ${mo}) install(FILES ${mo} DESTINATION ${CMAKE_INSTALL_LOCALEDIR}/${lang}/LC_MESSAGES) endforeach() add_custom_target(translations ALL DEPENDS ${OPENPU_MO_FILES}) # `cmake --build . --target pot` refreshes the template from the sources. find_program(XGETTEXT xgettext) if(XGETTEXT) add_custom_target(pot COMMAND ${XGETTEXT} --keyword=_ --keyword=N_ --from-code=UTF-8 --package-name=openpu --add-comments=TRANSLATORS -o ${CMAKE_CURRENT_SOURCE_DIR}/openpu.pot ${PROJECT_SOURCE_DIR}/src/ui-gtk/main_window.cpp ${PROJECT_SOURCE_DIR}/src/ui-haiku/main_window.cpp WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) endif()