Repository navigation
Expand file tree
/
Copy pathTranslationConfs.cmake
More file actions
64 lines (54 loc) · 2.71 KB
/
Copy pathTranslationConfs.cmake
File metadata and controls
64 lines (54 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Compilation and deployment of the UI translations (.ts -> .qm)
# The LinguistTools component (lrelease) is optional: without it the build
# goes on and the translations are simply not compiled/deployed
find_package(Qt6 6.4.0 QUIET COMPONENTS LinguistTools)
if(NOT TARGET Qt6::lrelease)
message(WARNING "Qt6 LinguistTools not found: the translations (.ts) will not be compiled nor deployed.")
endif()
# This function compiles the .ts files (the remaining arguments) in .qm files, using lrelease, and
# configures their deployment to INSTALL_DIR. The .qm files take the name of the .ts files
# (e.g. pt_BR.ts -> pt_BR.qm) and are generated under <current binary dir>/lang. The compilation
# is done by the target TARGET, which is part of the default build.
function(pgm_add_translations TARGET INSTALL_DIR)
if(NOT TARGET Qt6::lrelease)
return()
endif()
set(_QM_DIR ${CMAKE_CURRENT_BINARY_DIR}/lang)
foreach(_TS ${ARGN})
get_filename_component(_NAME ${_TS} NAME_WLE)
set(_QM ${_QM_DIR}/${_NAME}.qm)
add_custom_command(
OUTPUT ${_QM}
COMMAND ${CMAKE_COMMAND} -E make_directory ${_QM_DIR}
COMMAND Qt6::lrelease ${_TS} -qm ${_QM}
DEPENDS ${_TS}
COMMENT "Compiling translation ${_NAME}.qm"
VERBATIM)
list(APPEND _QM_FILES ${_QM})
endforeach()
add_custom_target(${TARGET} ALL DEPENDS ${_QM_FILES})
install(FILES ${_QM_FILES}
DESTINATION ${INSTALL_DIR})
endfunction()
# Language(s) of the dictionaries (.ts) created/updated by the target update_ts: a list of codes in
# the form xx or xx_XX. To use another language without reconfiguring, set the environment variable
# PGM_TS_LANG when building the target (it takes precedence over this variable):
# PGM_TS_LANG=fr_FR cmake --build <build dir> --target update_ts
set(PGM_TS_LANG "pt_BR" CACHE STRING "Language code(s) of the dictionaries generated by the target update_ts (e.g. pt_BR, or a list: fr_FR;pt_PT)")
# The target is not part of the default build, it runs only when requested:
# cmake --build <build dir> --target update_ts
if(TARGET Qt6::lupdate)
add_custom_target(update_ts
COMMAND ${CMAKE_COMMAND}
-DPGM_SOURCE_DIR=${CMAKE_SOURCE_DIR}
-DPGM_APPS_DIR=${APPS_DIR}
-DPGM_LIBS_DIR=${LIBS_DIR}
-DPGM_PRIV_CORE_DIR=${PRIV_CORE_DIR}
-DPGM_PRIV_PLUGINS_DIR=${PRIV_PLUGINS_DIR}
-DLUPDATE=$<TARGET_FILE:Qt6::lupdate>
"-DPGM_TS_LANG=${PGM_TS_LANG}"
-P ${CMAKE_SOURCE_DIR}/UpdateTranslations.cmake
COMMENT "Updating the translation sources (.ts) of ${PGM_TS_LANG}"
VERBATIM
USES_TERMINAL)
endif()