find_program(MSGFMT_EXECUTABLE msgfmt REQUIRED)

file(GLOB BONGO_CORE_PO_FILES CONFIGURE_DEPENDS
    "${CMAKE_CURRENT_SOURCE_DIR}/bongo/*.po")
foreach(po_file IN LISTS BONGO_CORE_PO_FILES)
    get_filename_component(locale "${po_file}" NAME_WE)
    set(mo_file
        "${CMAKE_CURRENT_BINARY_DIR}/${locale}/LC_MESSAGES/bongo.mo")
    add_custom_command(OUTPUT "${mo_file}"
        COMMAND ${CMAKE_COMMAND} -E make_directory
                "${CMAKE_CURRENT_BINARY_DIR}/${locale}/LC_MESSAGES"
        COMMAND ${MSGFMT_EXECUTABLE} --check -o "${mo_file}" "${po_file}"
        DEPENDS "${po_file}"
        VERBATIM)
    list(APPEND BONGO_CORE_CATALOGS "${mo_file}")
    install(FILES "${mo_file}"
            DESTINATION ${LOCALEDIR}/${locale}/LC_MESSAGES)
endforeach()

add_custom_target(bongo-core-translations ALL
    DEPENDS ${BONGO_CORE_CATALOGS})
