2018-09-22 16:28:19 +00:00
|
|
|
set(xlf_file "en_US/FlightGear-Qt.xlf")
|
2018-08-27 12:20:23 +00:00
|
|
|
|
2018-09-22 16:28:19 +00:00
|
|
|
if(EXISTS "${TRANSLATIONS_SRC_DIR}/${xlf_file}")
|
2018-08-27 12:20:23 +00:00
|
|
|
message(STATUS "Using explicitly defined translations from: ${TRANSLATIONS_SRC_DIR}")
|
|
|
|
set(do_translate TRUE)
|
2019-04-25 16:45:52 +00:00
|
|
|
elseif(EXISTS "${FG_DATA_DIR}/Translations/${xlf_file}")
|
|
|
|
set(TRANSLATIONS_SRC_DIR "${FG_DATA_DIR}/Translations")
|
2018-08-27 12:20:23 +00:00
|
|
|
set(do_translate TRUE)
|
2019-04-25 16:45:52 +00:00
|
|
|
message(STATUS "Found translations dir implicitly: ${TRANSLATIONS_SRC_DIR}")
|
2018-08-27 12:20:23 +00:00
|
|
|
else()
|
|
|
|
message(STATUS "Couldn't find translations data, will not include translated string in the executable")
|
2018-09-01 15:22:08 +00:00
|
|
|
set(do_translate FALSE)
|
2018-08-27 12:20:23 +00:00
|
|
|
endif()
|
|
|
|
|
2018-09-01 13:59:24 +00:00
|
|
|
find_package(Qt5 5.4 COMPONENTS LinguistTools)
|
|
|
|
if (${do_translate} AND NOT TARGET Qt5::lrelease)
|
|
|
|
set(do_translate FALSE)
|
|
|
|
message(STATUS "Built-in translations disabled becuase Qt5 lrelease tool was not found."
|
|
|
|
"\n(on Linux You may need to install an additional package containing the Qt5 translation tools)")
|
|
|
|
endif()
|
|
|
|
|
2020-05-13 14:01:50 +00:00
|
|
|
|
|
|
|
function(translation_dir_list result curdir)
|
|
|
|
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
|
|
|
|
set(dirlist "")
|
|
|
|
foreach(child ${children})
|
|
|
|
if (${child} STREQUAL "default")
|
|
|
|
continue()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (IS_DIRECTORY ${curdir}/${child})
|
|
|
|
list(APPEND dirlist ${child})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
set(${result} ${dirlist} PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
2018-08-27 12:20:23 +00:00
|
|
|
if (${do_translate})
|
2020-05-13 22:35:53 +00:00
|
|
|
translation_dir_list(LANGUAGES ${TRANSLATIONS_SRC_DIR})
|
|
|
|
message(STATUS "Detected language files: ${LANGUAGES}")
|
|
|
|
|
2018-08-27 12:20:23 +00:00
|
|
|
set(translation_res "${PROJECT_BINARY_DIR}/translations.qrc")
|
|
|
|
|
|
|
|
add_custom_target(fgfs_qm_files ALL)
|
|
|
|
|
2018-08-28 22:34:44 +00:00
|
|
|
file(WRITE ${translation_res} "<RCC>\n<qresource prefix=\"/\">\n")
|
2018-08-27 12:20:23 +00:00
|
|
|
|
|
|
|
# qm generation and installation
|
|
|
|
foreach(LANG ${LANGUAGES})
|
2020-05-12 12:36:28 +00:00
|
|
|
# avoid issue if the FGData we found is a different version, and a translation is
|
|
|
|
# missing: just skip it
|
|
|
|
if (NOT EXISTS ${TRANSLATIONS_SRC_DIR}/${LANG}/FlightGear-Qt.xlf)
|
|
|
|
continue()
|
|
|
|
endif()
|
|
|
|
|
2020-05-08 13:54:53 +00:00
|
|
|
set(out_file "${PROJECT_BINARY_DIR}/FlightGear_${LANG}.qm")
|
2018-08-27 12:20:23 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${out_file}
|
|
|
|
COMMAND Qt5::lrelease ${TRANSLATIONS_SRC_DIR}/${LANG}/FlightGear-Qt.xlf
|
|
|
|
-qm ${out_file}
|
|
|
|
DEPENDS ${TRANSLATIONS_SRC_DIR}/${LANG}/FlightGear-Qt.xlf
|
|
|
|
)
|
2020-05-08 13:54:53 +00:00
|
|
|
add_custom_target(fgfs_${LANG}_qm ALL DEPENDS ${out_file})
|
2018-08-27 12:20:23 +00:00
|
|
|
|
2020-05-08 13:54:53 +00:00
|
|
|
add_dependencies(fgfs_qm_files fgfs_${LANG}_qm)
|
2018-08-27 12:20:23 +00:00
|
|
|
|
|
|
|
# local path needed here, not absolute
|
2020-05-08 13:54:53 +00:00
|
|
|
file(APPEND ${translation_res} "<file>FlightGear_${LANG}.qm</file>\n")
|
2018-08-27 12:20:23 +00:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
file(APPEND ${translation_res} "</qresource>\n</RCC>")
|
2018-08-28 16:12:31 +00:00
|
|
|
|
|
|
|
# set this so config.h can detect it
|
|
|
|
set(HAVE_QRC_TRANSLATIONS TRUE)
|
2020-05-13 22:35:53 +00:00
|
|
|
|
|
|
|
add_custom_target(ts)
|
|
|
|
|
|
|
|
foreach(lang ${LANGUAGES})
|
|
|
|
add_custom_target(
|
|
|
|
ts_${lang}
|
|
|
|
COMMAND Qt5::lupdate ${CMAKE_SOURCE_DIR}/src/GUI
|
|
|
|
-locations relative -no-ui-lines -ts ${TRANSLATIONS_SRC_DIR}/${lang}/FlightGear-Qt.xlf
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
)
|
|
|
|
add_dependencies(ts ts_${lang})
|
|
|
|
endforeach()
|
2018-09-01 15:22:08 +00:00
|
|
|
endif() # of do translate
|
2020-03-10 17:25:03 +00:00
|
|
|
|