# Copyright (c) 2025-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.

include(ts_files.cmake)

# lrelease merges upstream and ReSatoshi-only catalogs directly into one .qm.
file(GLOB resatoshi_catalogs CONFIGURE_DEPENDS "${PROJECT_SOURCE_DIR}/src/qt/resatoshi_locale/*.ts")
set(qm_files)
foreach(ts_file IN LISTS ts_files)
  set(inputs "${CMAKE_CURRENT_SOURCE_DIR}/${ts_file}")
  string(REPLACE "bitcoin_" "resatoshi_" overlay_name "${ts_file}")
  set(overlay "${PROJECT_SOURCE_DIR}/src/qt/resatoshi_locale/${overlay_name}")
  if(EXISTS "${overlay}")
    list(APPEND inputs "${overlay}")
  endif()
  string(REGEX REPLACE "\\.ts$" ".qm" qm_file "${ts_file}")
  set(qm_file "${CMAKE_CURRENT_BINARY_DIR}/${qm_file}")
  add_custom_command(OUTPUT "${qm_file}"
    COMMAND Qt6::lrelease -silent ${inputs} -qm "${qm_file}"
    DEPENDS ${inputs} Qt6::lrelease
    VERBATIM
  )
  list(APPEND qm_files "${qm_file}")
endforeach()
add_custom_target(bitcoinqt_lrelease DEPENDS ${qm_files})
add_dependencies(bitcoinqt bitcoinqt_lrelease)
