1 # Generate translations
2 # The LINGUAS environment variable can be used to limit the set of supported languages
4 # Generate a .ts file from a .po file
5 function(generate_ts basename)
6 set(pofile ${CMAKE_CURRENT_SOURCE_DIR}/${basename}.po)
7 set(tsfile ${CMAKE_CURRENT_BINARY_DIR}/${basename}.ts)
9 add_custom_command(VERBATIM
10 COMMENT "Preparing translation for language '${basename}'"
11 COMMAND $<TARGET_FILE:Qt5::lconvert> -i ${pofile} -target-language ${basename} -of ts -o ${tsfile}
17 # Clear variables just in case
22 if (TARGET Qt5::lconvert)
23 # LINGUAS can be used to limit the included languages
24 set(LINGUAS "$ENV{LINGUAS}")
25 # Normalize and convert into list
26 string(REGEX REPLACE "[ \t,;]+" ";" LINGUAS "${LINGUAS}")
28 # We support xx.po and xx_YY.po, and additionally translations for qt using qt_xx.po or qt_xx_YY.po
29 file(GLOB pofiles *.po)
30 foreach(pofile ${pofiles})
31 get_filename_component(basename ${pofile} NAME_WE)
32 # CMake can't use MATCH to get the second catch...
33 string(REGEX REPLACE "(qt_)?([a-zA-Z]+)(_.+)?$" "\\2" lang ${basename})
34 # Test if we want this language
37 list(FIND LINGUAS ${lang} idx) # idx will be -1 if ${lang} is not found in LINGUAS
40 generate_ts(${basename})
41 list(APPEND tsfiles ${CMAKE_CURRENT_BINARY_DIR}/${basename}.ts)
42 list(APPEND qmfiles ${CMAKE_CURRENT_BINARY_DIR}/${basename}.qm)
43 list(APPEND linguas ${lang})
48 # Synchronize the (possibly outdated) .ts files with the current source tree
49 add_custom_command(VERBATIM
50 COMMENT "Syncing translations"
51 COMMAND $<TARGET_FILE:Qt5::lupdate> -silent ${CMAKE_SOURCE_DIR}/src -ts ${tsfiles}
52 COMMAND ${CMAKE_COMMAND} -E touch tsfiles.done
57 # Generate the final translation files (.qm) for use by Qt
58 add_custom_command(VERBATIM
59 COMMENT "Compressing translations"
60 COMMAND $<TARGET_FILE:Qt5::lrelease> -silent ${tsfiles}
65 # Curate the language list and give diagnostic output
66 list(REMOVE_DUPLICATES linguas)
68 string(REPLACE ";" ", " linguas_string "${linguas}")
69 message(STATUS "Enabling translations for: ${linguas_string}")
71 message(STATUS "No translations enabled")
74 message(WARNING "Qt Linguist Tools not found, you won't have translations!")
77 # Always generate translations
78 add_custom_target(translations ALL DEPENDS ${qmfiles})
81 quassel_add_resource(I18n PREFIX i18n BASEDIR ${CMAKE_CURRENT_BINARY_DIR} PATTERNS ${qmfiles} DEPENDS translations)
83 install(FILES ${qmfiles} DESTINATION ${CMAKE_INSTALL_DATADIR}/quassel/translations)