- # test if we want this language
- set(flg 1)
- if(LINGUAS)
- string(REGEX MATCH "${lang}" flg ${LINGUAS})
- endif()
- if(flg)
- generate_ts(QM ${basename})
- generate_qm(QM ${basename})
- list(APPEND qm_files ${QM})
- list(APPEND gen_linguas ${lang})
+ # We support xx.po and xx_YY.po, and additionally translations for qt using qt_xx.po or qt_xx_YY.po
+ file(GLOB pofiles *.po)
+ foreach(pofile ${pofiles})
+ get_filename_component(basename ${pofile} NAME_WE)
+ # CMake can't use MATCH to get the second catch...
+ string(REGEX REPLACE "(qt_)?([a-zA-Z]+)(_.+)?$" "\\2" lang ${basename})
+ # Test if we want this language
+ set(idx 0)
+ if(LINGUAS)
+ list(FIND LINGUAS ${lang} idx) # idx will be -1 if ${lang} is not found in LINGUAS
+ endif()
+ if(idx GREATER -1)
+ generate_ts(${basename})
+ list(APPEND tsfiles ${CMAKE_CURRENT_BINARY_DIR}/${basename}.ts)
+ list(APPEND qmfiles ${CMAKE_CURRENT_BINARY_DIR}/${basename}.qm)
+ list(APPEND linguas ${lang})
+ endif()
+ endforeach()
+
+ if (tsfiles)
+ # Synchronize the (possibly outdated) .ts files with the current source tree
+ add_custom_command(VERBATIM
+ COMMENT "Syncing translations"
+ COMMAND $<TARGET_FILE:Qt5::lupdate> -silent ${CMAKE_SOURCE_DIR}/src -ts ${tsfiles}
+ COMMAND ${CMAKE_COMMAND} -E touch tsfiles.done
+ DEPENDS ${tsfiles}
+ OUTPUT tsfiles.depends
+ )
+
+ # Generate the final translation files (.qm) for use by Qt
+ add_custom_command(VERBATIM
+ COMMENT "Compressing translations"
+ COMMAND $<TARGET_FILE:Qt5::lrelease> -silent ${tsfiles}
+ DEPENDS tsfiles.depends
+ OUTPUT ${qmfiles}
+ )
+
+ # Curate the language list and give diagnostic output
+ list(REMOVE_DUPLICATES linguas)
+ list(SORT linguas)
+ string(REPLACE ";" ", " linguas_string "${linguas}")
+ message(STATUS "Enabling translations for: ${linguas_string}")
+ else()
+ message(STATUS "No translations enabled")