1
0
Fork 0
flightgear/CMakeModules/Translations.cmake
Florent Rougon b2d6acdd4d CMake changes related to FGDATA_SRC_DIR and TRANSLATIONS_SRC_DIR
- When FGDATA_SRC_DIR isn't explicitly set by the user, set it to
  ${PROJECT_SOURCE_DIR}/../fgdata if this is a directory.

- When TRANSLATIONS_SRC_DIR isn't explicitly set by the user, look for
  translations in ${FGDATA_SRC_DIR}/Translations instead of
  ${PROJECT_SOURCE_DIR}/../fgdata/Translations (i.e., honor the setting
  of FGDATA_SRC_DIR for the sake of translation lookup).

This fixes the problem explained in [1] and [2].

[1] https://sourceforge.net/p/flightgear/mailman/message/36645499/
[2] b2274fbbed/
2019-04-25 19:11:01 +02:00

57 lines
2.3 KiB
CMake

set(xlf_file "en_US/FlightGear-Qt.xlf")
if(EXISTS "${TRANSLATIONS_SRC_DIR}/${xlf_file}")
message(STATUS "Using explicitly defined translations from: ${TRANSLATIONS_SRC_DIR}")
set(do_translate TRUE)
elseif(EXISTS "${FG_DATA_DIR}/Translations/${xlf_file}")
set(TRANSLATIONS_SRC_DIR "${FG_DATA_DIR}/Translations")
set(do_translate TRUE)
message(STATUS "Found translations dir implicitly: ${TRANSLATIONS_SRC_DIR}")
else()
message(STATUS "Couldn't find translations data, will not include translated string in the executable")
set(do_translate FALSE)
endif()
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()
if (${do_translate})
# FIXME - determine this based on subdirs of TRANSLATIONS_SRC_DIR
set(LANGUAGES en_US de es nl fr it pl pt ru zh_CN)
set(translation_res "${PROJECT_BINARY_DIR}/translations.qrc")
add_custom_target(fgfs_qm_files ALL)
file(WRITE ${translation_res} "<RCC>\n<qresource prefix=\"/\">\n")
# qm generation and installation
foreach(LANG ${LANGUAGES})
# trim down to a two-letter code for output. This will need to get
# smarter if we ever have different translations for a dialect,
# eg en_GB, fr_CA or pt_BR.
string(SUBSTRING ${LANG} 0 2 simple_lang)
set(out_file "${PROJECT_BINARY_DIR}/FlightGear_${simple_lang}.qm")
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
)
add_custom_target(fgfs_${simple_lang}_qm ALL DEPENDS ${out_file})
add_dependencies(fgfs_qm_files fgfs_${simple_lang}_qm)
# local path needed here, not absolute
file(APPEND ${translation_res} "<file>FlightGear_${simple_lang}.qm</file>\n")
endforeach()
file(APPEND ${translation_res} "</qresource>\n</RCC>")
# set this so config.h can detect it
set(HAVE_QRC_TRANSLATIONS TRUE)
endif() # of do translate