1 # check for lupdate and lrelease: we can't
2 # do it using qmake as it doesn't have
3 # QMAKE_LUPDATE and QMAKE_LRELEASE variables :(
5 # I18N_LANGUAGE - if not empty, wraps only chosen language
8 get_filename_component(LINGUIST_PATH ${Qt5LinguistTools_DIR} PATH)
9 get_filename_component(LINGUIST_PATH ${LINGUIST_PATH} PATH)
10 get_filename_component(LINGUIST_PATH ${LINGUIST_PATH} PATH)
11 set(LINGUIST_PATH ${LINGUIST_PATH}/bin)
13 if(TARGET Qt5::lupdate)
14 set(QT_LUPDATE_EXECUTABLE Qt5::lupdate)
15 else(TARGET Qt5::lupdate)
16 FIND_PROGRAM(QT_LUPDATE_EXECUTABLE NAMES lupdate-qt5 lupdate PATHS
20 endif(TARGET Qt5::lupdate)
22 if(QT_LUPDATE_EXECUTABLE)
23 message(STATUS "Found lupdate: ${QT_LUPDATE_EXECUTABLE}")
24 else(QT_LUPDATE_EXECUTABLE)
25 if(Qt5LinguistForTrojita_FIND_REQUIRED)
26 message(FATAL_ERROR "Could NOT find lupdate")
28 message(WARNING "Could NOT find lupdate")
30 endif(QT_LUPDATE_EXECUTABLE)
32 if(TARGET Qt5::lrelease)
33 set(QT_LRELEASE_EXECUTABLE Qt5::lrelease)
34 else(TARGET Qt5::lrelease)
35 FIND_PROGRAM(QT_LRELEASE_EXECUTABLE NAMES lrelease-qt5 lrelease PATHS
39 endif(TARGET Qt5::lrelease)
41 if(QT_LRELEASE_EXECUTABLE)
42 message(STATUS "Found lrelease: ${QT_LRELEASE_EXECUTABLE}")
43 else(QT_LRELEASE_EXECUTABLE)
44 if(Qt5LinguistForTrojita_FIND_REQUIRED)
45 message(FATAL_ERROR "Could NOT find lrelease")
47 message(WARNING "Could NOT find lrelease")
49 endif(QT_LRELEASE_EXECUTABLE)
51 if(TARGET Qt5::lconvert)
52 set(QT_LCONVERT_EXECUTABLE Qt5::lconvert)
53 else(TARGET Qt5::lconvert)
54 FIND_PROGRAM(QT_LCONVERT_EXECUTABLE NAMES lconvert-qt5 lconvert PATHS
58 endif(TARGET Qt5::lconvert)
60 if(QT_LCONVERT_EXECUTABLE)
61 message(STATUS "Found lconvert: ${QT_LCONVERT_EXECUTABLE}")
62 else(QT_LCONVERT_EXECUTABLE)
63 if(Qt5LinguistForTrojita_FIND_REQUIRED)
64 message(FATAL_ERROR "Could NOT find lconvert")
66 message(WARNING "Could NOT find lconvert")
68 endif(QT_LCONVERT_EXECUTABLE)
70 mark_as_advanced(QT_LUPDATE_EXECUTABLE QT_LRELEASE_EXECUTABLE QT_LCONVERT_EXECUTABLE)
72 if(QT_LUPDATE_EXECUTABLE AND QT_LRELEASE_EXECUTABLE AND QT_LCONVERT_EXECUTABLE)
73 set(Qt5LinguistForTrojita_FOUND TRUE)
75 # QT5_WRAP_TS(outfiles infiles ...)
76 # outfiles receives .qm generated files from
77 # .ts files in arguments
78 # a target lupdate is created for you
79 # update/generate your translations files
80 # example: QT5_WRAP_TS(foo_QM ${foo_TS})
81 MACRO (QT5_WRAP_TS outfiles)
82 # a target to manually run lupdate
83 #ADD_CUSTOM_TARGET(lupdate
84 #COMMAND ${QT_LUPDATE_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR} -ts ${ARGN}
85 #WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
88 GET_FILENAME_COMPONENT(it ${it} ABSOLUTE)
89 GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)
91 SET(outfile ${CMAKE_CURRENT_BINARY_DIR}/${outfile}.qm)
92 ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
93 COMMAND ${QT_LRELEASE_EXECUTABLE}
94 ARGS -compress -removeidentical -silent ${it} -qm ${outfile}
98 SET(${outfiles} ${${outfiles}} ${outfile})
100 ENDMACRO (QT5_WRAP_TS)
102 # QT_WRAP_PO(outfiles infiles ...)
103 # outfiles receives .qm generated files from
104 # .po files in arguments
105 # example: QT5_WRAP_PO(foo_TS ${foo_PO})
106 MACRO (QT5_WRAP_PO outfiles)
108 GET_FILENAME_COMPONENT(it ${it} ABSOLUTE)
109 # PO files are foo-en_GB.po not foo_en_GB.po like Qt expects
110 GET_FILENAME_COMPONENT(fileWithDash ${it} NAME_WE)
111 if(NOT I18N_LANGUAGE)
113 else(NOT I18N_LANGUAGE)
114 string(REGEX MATCH "${I18N_LANGUAGE}" ln ${fileWithDash})
120 endif(NOT I18N_LANGUAGE)
122 STRING(REPLACE "-" "_" filenameBase "${fileWithDash}")
123 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/locale)
124 SET(tsfile ${CMAKE_CURRENT_BINARY_DIR}/locale/${filenameBase}.ts)
125 SET(qmfile ${CMAKE_CURRENT_BINARY_DIR}/locale/${filenameBase}.qm)
127 if (NOT EXISTS "${it}")
128 GET_FILENAME_COMPONENT(path ${it} PATH)
129 STRING(REGEX MATCH "[^-]+$" lang "${fileWithDash}")
130 set (it "${path}/${lang}.po")
131 endif (NOT EXISTS "${it}")
133 # lconvert from PO to TS and then run lupdate to generate the correct strings
134 # finally run lrelease as used above
135 ADD_CUSTOM_COMMAND(OUTPUT ${qmfile}
136 COMMAND ${QT_LCONVERT_EXECUTABLE}
137 ARGS -i ${it} -o ${tsfile}
138 COMMAND ${QT_LUPDATE_EXECUTABLE}
139 ARGS ${CMAKE_CURRENT_SOURCE_DIR} -silent -noobsolete -ts ${tsfile}
140 COMMAND ${QT_LRELEASE_EXECUTABLE}
141 ARGS -compress -removeidentical -nounfinished -silent ${tsfile} -qm ${qmfile}
145 SET(${outfiles} ${${outfiles}} ${qmfile})
148 ENDMACRO (QT5_WRAP_PO)
150 else(QT_LUPDATE_EXECUTABLE AND QT_LRELEASE_EXECUTABLE AND QT_LCONVERT_EXECUTABLE)
151 set(Qt5LinguistForTrojita_FOUND FALSE)
152 endif(QT_LUPDATE_EXECUTABLE AND QT_LRELEASE_EXECUTABLE AND QT_LCONVERT_EXECUTABLE)