Computer Assisted Medical Intervention Tool Kit  version 5.2
CamiTKTranslate.h
Go to the documentation of this file.
17 
18  if(NOT CAMITK_DISABLE_TRANSLATION) #To allow enabling or not translation, directly from CMake configure command
19 
20  set(options USE_FLAGS)
21  set(oneValueArgs "")
22  set(multiValueArgs EXTRA_LANGUAGE)
23  cmake_parse_arguments(CAMITK_TRANSLATION "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
24 
25  #insert here your new language _xx
26  set(CAMITK_TRANSLATIONS _en_fr)
27 
28  if(CAMITK_TRANSLATION_EXTRA_LANGUAGE)
29  set(CAMITK_TRANSLATIONS ${CAMITK_TRANSLATIONS}_${CAMITK_TRANSLATION_EXTRA_LANGUAGE})
30  endif()
31 
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")
37 
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 " ")
42  endforeach()
43 
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 " ")
48  endforeach()
49 
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 " ")
54  endforeach()
55 
56  file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate/translate.pro "\nTRANSLATIONS = ")
57 
58  string(TOLOWER ${CAMITK_TRANSLATIONS} CAMITK_TRANSLATIONS)
59  string(LENGTH ${CAMITK_TRANSLATIONS} longueur)
60  string(FIND ${CAMITK_TRANSLATIONS} "_" index)
61 
62  while(index GREATER -1)
63  string(SUBSTRING ${CAMITK_TRANSLATIONS} ${index} 3 language)
64 
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 " ")
67 
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)
72 
73  string(LENGTH ${CAMITK_TRANSLATIONS} longueur)
74  string(FIND ${CAMITK_TRANSLATIONS} "_" index)
75 
76  endwhile(index GREATER -1)
77 
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)
84 
85  # remove the translate.pro file
86  file(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate/translate.pro)
87 
88 
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)
93  get_directory_name(${CMAKE_CURRENT_SOURCE_DIR} EXTENSION_NAME)
94 
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")
100 
101  file (GLOB QM_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate ${CMAKE_CURRENT_SOURCE_DIR}/resources/translate/*.qm)
102  foreach(F ${QM_FILES})
103  file(APPEND ${TRANSLATE_QRC_FILE} "\t\t<file>translate/${F}</file>\n")
104  endforeach(F ${QM_FILES})
105 
106  file(APPEND ${TRANSLATE_QRC_FILE} "\t</qresource>\n")
107  file(APPEND ${TRANSLATE_QRC_FILE} "</RCC>\n")
108 
109  #create the flags.qrc file
110  if(CAMITK_TRANSLATION_USE_FLAGS)
111  file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/resources/flags.qrc "<!DOCTYPE RCC>\n")
112  file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/resources/flags.qrc "<RCC version=\"1.0\">\n")
113  file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/resources/flags.qrc "\t<qresource prefix=\"/flags\">\n")
114 
115  file(GLOB PNG_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/resources ${CMAKE_CURRENT_SOURCE_DIR}/resources/flags/16/*.png)
116 
117  foreach(F ${PNG_FILES})
118  file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/resources/flags.qrc "\t\t<file>${F}</file>\n")
119  endforeach(F ${PNG_FILES})
120 
121  file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/resources/flags.qrc "\t</qresource>\n")
122  file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/resources/flags.qrc "</RCC>\n")
123  endif()
124  endif()
125 end(){)
cmake modules macros camitk test endif() add_custom_target(camitk-ce-iwyu COMMAND $
Definition: CamiTKIncludeWhatYouUse.h:37
#define a
iwyu out CACHE PATH Output filename for include what you use set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${IWYU_EXECUTABLE}) if(NOT EXISTS $
Definition: CamiTKIncludeWhatYouUse.h:22
test result execute_process(COMMAND ${CMAKE_COMMAND} -E remove -f ${CAMITK_TEST_COMMAND_FILE} ${CAMITK_TEST_COMMAND_RESULT_FILE} ${CAMITK_TEST_COMMAND_OUTPUT_FILE} ${CAMITK_TEST_PASS_FILE_COMMAND_FILE} ${CAMITK_TEST_PASS_FILE_OUTPUT_FILE} ${CAMITK_TEST_PASS_FILE_RESULT_FILE}) file(WRITE $
Definition: CamiTKTestPassFile.h:21
camitk_translate()
macro camitk_translate allows to perform the translation of any project (action, component,...
Definition: CamiTKTranslate.h:16
get_directory_name()
macro get_directory_name set the variable VariableName to the name of the last directory of FullPathD...
Definition: GetDirectoryName.h:14