2025-10-15 02:39:45 +00:00
|
|
|
# SPDX-FileCopyrightText: Chris Rizzitello <sithlord48@gmail.com>
|
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
|
set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM 1)
|
|
|
|
|
option(CLEAN_TRS "Clean obsolete translations from tr files" OFF)
|
|
|
|
|
find_package(Qt6 ${REQUIRED_QT_VERSION} REQUIRED NO_MODULE COMPONENTS LinguistTools)
|
|
|
|
|
|
|
|
|
|
# To add a new language Add 639 shortname
|
|
|
|
|
set (${CMAKE_PROJECT_NAME}_TRS
|
|
|
|
|
${CMAKE_PROJECT_NAME}_es.ts
|
2025-11-02 10:56:52 +00:00
|
|
|
${CMAKE_PROJECT_NAME}_it.ts
|
2025-11-18 05:56:59 +00:00
|
|
|
${CMAKE_PROJECT_NAME}_ja.ts
|
2025-11-19 06:51:20 +00:00
|
|
|
${CMAKE_PROJECT_NAME}_zh_CN.ts
|
2025-11-19 15:40:33 +00:00
|
|
|
${CMAKE_PROJECT_NAME}_ru.ts
|
2025-10-15 02:39:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
set(TR_OPTIONS -no-ui-lines -locations none -silent)
|
|
|
|
|
if(CLEAN_TRS)
|
|
|
|
|
list(APPEND TR_OPTIONS -no-obsolete)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# English will have only plurals
|
|
|
|
|
qt_create_translation(TRS ${CMAKE_SOURCE_DIR}/src ${CMAKE_PROJECT_NAME}_en.ts OPTIONS -pluralonly ${TR_OPTIONS})
|
|
|
|
|
|
|
|
|
|
# Other languages contain the full set of strings.
|
|
|
|
|
qt_create_translation(TRS ${CMAKE_SOURCE_DIR}/src ${${CMAKE_PROJECT_NAME}_TRS} OPTIONS ${TR_OPTIONS})
|
|
|
|
|
|
|
|
|
|
#ensure that the targets are built always
|
|
|
|
|
add_custom_target(app_translations ALL DEPENDS ${TRS})
|
|
|
|
|
|
2025-11-08 16:00:34 +00:00
|
|
|
# install our translations
|
|
|
|
|
install(FILES ${TRS} DESTINATION ${CMAKE_INSTALL_I18N_DIR})
|
2025-10-15 02:39:45 +00:00
|
|
|
|
2025-11-08 16:00:34 +00:00
|
|
|
if(APPLE)
|
2025-10-15 02:39:45 +00:00
|
|
|
# find the qt translation files not deployed by macdeployqt
|
|
|
|
|
get_target_property(lupdate_executable Qt6::lupdate IMPORTED_LOCATION)
|
|
|
|
|
get_filename_component(_qt_bin_dir "${lupdate_executable}" DIRECTORY)
|
|
|
|
|
file(REAL_PATH "${_qt_bin_dir}/../" QT_ROOT_DIR)
|
|
|
|
|
find_file(_QT_QM_FILE NAMES qtbase_en.qm PATHS ${QT_ROOT_DIR} PATH_SUFFIXES "translations" "share/qt/translations" REQUIRED)
|
|
|
|
|
get_filename_component(MAC_QT_LANG_PATH "${_QT_QM_FILE}" DIRECTORY)
|
|
|
|
|
|
|
|
|
|
# install each lang file and rename to the same name
|
|
|
|
|
# rename does not work with a list so foreach is used instead
|
2025-11-08 16:00:34 +00:00
|
|
|
install(FILES ${MAC_QT_LANG_PATH}/qtbase_en.qm DESTINATION ${CMAKE_INSTALL_I18N_DIR} RENAME qt_en.qm)
|
2025-10-15 02:39:45 +00:00
|
|
|
foreach(LANG ${${CMAKE_PROJECT_NAME}_TRS})
|
|
|
|
|
string(REPLACE "${CMAKE_PROJECT_NAME}_" "" LANG ${LANG})
|
|
|
|
|
string(REPLACE ".ts" "" LANG ${LANG})
|
2025-11-08 16:00:34 +00:00
|
|
|
install(FILES ${MAC_QT_LANG_PATH}/qtbase_${LANG}.qm DESTINATION ${CMAKE_INSTALL_I18N_DIR} RENAME qt_${LANG}.qm)
|
2025-10-15 02:39:45 +00:00
|
|
|
endforeach()
|
|
|
|
|
endif()
|