18 if(NOT CAMITK_DISABLE_TRANSLATION) #To allow enabling or not translation, directly from CMake configure command
20 set(options USE_FLAGS)
22 set(multiValueArgs EXTRA_LANGUAGE)
23 cmake_parse_arguments(CAMITK_TRANSLATION
"${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
25 #insert here your
new language _xx
26 set(CAMITK_TRANSLATIONS _en_fr)
28 if(CAMITK_TRANSLATION_EXTRA_LANGUAGE)
29 set(CAMITK_TRANSLATIONS ${CAMITK_TRANSLATIONS}_${CAMITK_TRANSLATION_EXTRA_LANGUAGE})
32 #create translate.pro file
33 file (GLOB HEADER_FILES *.h *.hpp)
34 file (GLOB CPP_FILES *.cpp)
35 file (GLOB UI_FILES *.ui)
36 set (FILES_TO_TRANSLATE ${FILES_TO_TRANSLATE} ${CPP_FILES} ${UI_FILES} ${HEADER_FILES} CACHE INTERNAL
"Files to translate")
38 file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate/translate.pro
"\nHEADERS = ")
39 foreach(F ${HEADER_FILES})
40 file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate/translate.pro ${F})
41 file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate/translate.pro
" ")
44 file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate/translate.pro
"\nSOURCES = ")
45 foreach(F ${CPP_FILES})
46 file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate/translate.pro ${F})
47 file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate/translate.pro
" ")
50 file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate/translate.pro
"\nFORMS = ")
51 foreach(F ${UI_FILES})
52 file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate/translate.pro ${F})
53 file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate/translate.pro
" ")
56 file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate/translate.pro
"\nTRANSLATIONS = ")
58 string(TOLOWER ${CAMITK_TRANSLATIONS} CAMITK_TRANSLATIONS)
59 string(LENGTH ${CAMITK_TRANSLATIONS} longueur)
60 string(FIND ${CAMITK_TRANSLATIONS}
"_" index)
62 while(index GREATER -1)
63 string(SUBSTRING ${CAMITK_TRANSLATIONS} ${index} 3 language)
65 file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate/translate.pro ${CMAKE_CURRENT_BINARY_DIR}/translate${language}.ts)
66 file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate/translate.pro
" ")
68 string(LENGTH ${CAMITK_TRANSLATIONS} longueur)
69 math(EXPR index
"${index} + 1 ")
70 math(EXPR longueur
"${longueur} - ${index}")
71 string(SUBSTRING ${CAMITK_TRANSLATIONS} ${index} ${longueur} CAMITK_TRANSLATIONS)
73 string(LENGTH ${CAMITK_TRANSLATIONS} longueur)
74 string(FIND ${CAMITK_TRANSLATIONS}
"_" index)
76 endwhile(index GREATER -1)
78 #update translate_xx.ts files and create translate_xx.qm files
79 set(WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate )
80 find_path(QT_BINARY_DIR NAMES lupdate)
81 execute_process (COMMAND ${QT_BINARY_DIR}/lupdate -silent ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate/translate.pro)
82 find_path(QT_BINARY_DIR NAMES lrelease)
83 execute_process (COMMAND ${QT_BINARY_DIR}/lrelease -silent ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate/translate.pro)
85 # remove the translate.pro file
86 file(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate/translate.pro)
89 # create the translate_extension_name.qrc file
90 # Remember that the .qrc filename must be unique
91 # Also, when having loaded all .qrc files within the application, you have to point on
92 # each .qm file separately (i.e. use
a specific prefix on each .qrc file)
95 #create the translate.qrc file
96 set(TRANSLATE_QRC_FILE ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate_${EXTENSION_NAME}.qrc)
97 file(WRITE ${TRANSLATE_QRC_FILE}
"<!DOCTYPE RCC>\n")
98 file(APPEND ${TRANSLATE_QRC_FILE}
"<RCC version=\"1.0\">\n")
99 file(APPEND ${TRANSLATE_QRC_FILE}
"\t<qresource prefix=\"/translate_${EXTENSION_NAME}\">\n")
101 file (GLOB QM_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate