Debian Codegraph @

CMakeModules/Translations.cmake

raw
1 set(xlf_file "en_US/FlightGear-Qt.xlf")
2
3 if(EXISTS "${TRANSLATIONS_SRC_DIR}/${xlf_file}")
4 message(STATUS "Using explicitly defined translations from: ${TRANSLATIONS_SRC_DIR}")
5 set(do_translate TRUE)
6 elseif(EXISTS "${FG_DATA_DIR}/Translations/${xlf_file}")
7 set(TRANSLATIONS_SRC_DIR "${FG_DATA_DIR}/Translations")
8 set(do_translate TRUE)
9 message(STATUS "Found translations dir implicitly: ${TRANSLATIONS_SRC_DIR}")
10 else()
11 message(STATUS "Couldn't find translations data, will not include translated string in the executable")
12 set(do_translate FALSE)
13 endif()
14
15 find_package(Qt${QT_VERSION_MAJOR} COMPONENTS LinguistTools)
16 if (${do_translate} AND NOT TARGET Qt${QT_VERSION_MAJOR}::lrelease)
17 set(do_translate FALSE)
18 message(STATUS "Built-in translations disabled becuase Qt lrelease tool was not found."
19 "\n(on Linux You may need to install an additional package containing the Qt translation tools)")
20 endif()
21
22
23 function(translation_dir_list result curdir)
24 file(GLOB children RELATIVE ${curdir} ${curdir}/*)
25 set(dirlist "")
26 foreach(child ${children})
27 if (${child} STREQUAL "default")
28 continue()
29 endif()
30
31 if (IS_DIRECTORY ${curdir}/${child})
32 list(APPEND dirlist ${child})
33 endif()
34 endforeach()
35 set(${result} ${dirlist} PARENT_SCOPE)
36 endfunction()
37
38 if (${do_translate})
39 translation_dir_list(LANGUAGES ${TRANSLATIONS_SRC_DIR})
40 message(STATUS "Detected language files: ${LANGUAGES}")
41
42 set(translation_res "${PROJECT_BINARY_DIR}/translations.qrc")
43
44 add_custom_target(fgfs_qm_files ALL)
45
46 file(WRITE ${translation_res} "<RCC>\n<qresource prefix=\"/\">\n")
47
48 # qm generation and installation
49 foreach(LANG ${LANGUAGES})
50 # avoid issue if the FGData we found is a different version, and a translation is
51 # missing: just skip it
52 if (NOT EXISTS ${TRANSLATIONS_SRC_DIR}/${LANG}/FlightGear-Qt.xlf)
53 continue()
54 endif()
55
56 set(out_file "${PROJECT_BINARY_DIR}/FlightGear_${LANG}.qm")
57 add_custom_command(
58 OUTPUT ${out_file}
59 COMMAND Qt${QT_VERSION_MAJOR}::lrelease ${TRANSLATIONS_SRC_DIR}/${LANG}/FlightGear-Qt.xlf
60 -qm ${out_file}
61 DEPENDS ${TRANSLATIONS_SRC_DIR}/${LANG}/FlightGear-Qt.xlf
62 )
63 add_custom_target(fgfs_${LANG}_qm ALL DEPENDS ${out_file})
64
65 add_dependencies(fgfs_qm_files fgfs_${LANG}_qm)
66
67 # fix for bug https://sourceforge.net/p/flightgear/codetickets/2406/
68 # ensure we expose the English translations in a 'short' form, so that
69 # the QTranslator search order finds it
70 if (${LANG} STREQUAL "en_US")
71 file(APPEND ${translation_res} "<file alias=\"FlightGear_en.qm\">FlightGear_${LANG}.qm</file>\n")
72 else()
73 # local path needed here, not absolute
74 file(APPEND ${translation_res} "<file>FlightGear_${LANG}.qm</file>\n")
75 endif()
76 endforeach()
77
78 file(APPEND ${translation_res} "</qresource>\n</RCC>")
79
80 # set this so config.h can detect it
81 set(HAVE_QRC_TRANSLATIONS TRUE)
82
83 add_custom_target(ts)
84
85 foreach(lang ${LANGUAGES})
86 add_custom_target(
87 ts_${lang}
88 COMMAND Qt${QT_VERSION_MAJOR}::lupdate ${CMAKE_SOURCE_DIR}/src/GUI
89 -locations relative -disable-heuristic similartext -no-ui-lines -ts ${TRANSLATIONS_SRC_DIR}/${lang}/FlightGear-Qt.xlf
90 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
91 )
92 add_dependencies(ts ts_${lang})
93 endforeach()
94 endif() # of do translate
95