1 # - Find GNU gettext tools
2 # This module looks for the GNU gettext tools. This module defines the
4 # GETTEXT_MSGMERGE_EXECUTABLE: the full path to the msgmerge tool.
5 # GETTEXT_MSGFMT_EXECUTABLE: the full path to the msgfmt tool.
6 # GETTEXT_FOUND: True if gettext has been found.
8 # Additionally it provides the following macros:
9 # GETTEXT_CREATE_TRANSLATIONS ( _moBasename [ALL] file1 ... fileN )
10 # This will create a target "translations" which will convert the
11 # given input po files into the binary output mo file. If the
12 # ALL option is used, the translations will also be created when
13 # building the default target.
15 FIND_PROGRAM(GETTEXT_MSGMERGE_EXECUTABLE msgmerge)
17 FIND_PROGRAM(GETTEXT_MSGFMT_EXECUTABLE msgfmt)
20 # Macro to be called if .po files are shipped as tar ball.
22 # _translation_set_basename: Serves two purposes; a) the stem of the
23 # default tarball %{_translation_set_basename}-po.tar.bz2 unless its over
24 # riden by -DUSE_TRANSLATION_SET; b) the basename of the .gmo files.
26 # We expect a po-file tarball to unpack the .po file to the current
29 MACRO( GETTEXT_CREATE_TARBALL_TRANSLATIONS _translation_set_basename )
31 IF( NOT USE_TRANSLATION_SET )
32 SET( USE_TRANSLATION_SET ${_translation_set_basename} )
33 ENDIF( NOT USE_TRANSLATION_SET )
35 SET( TRANSLATION_SET "${USE_TRANSLATION_SET}-po.tar.bz2" )
36 MESSAGE( STATUS "Translation set: ${TRANSLATION_SET}" )
38 # For those not familiar with 'sed': the tarball might list './' and './*.po'.
39 # We process just the '*.po' lines and strip off any leading './'.
41 COMMAND tar tfj ${CMAKE_CURRENT_SOURCE_DIR}/${TRANSLATION_SET}
42 COMMAND sed -n "/\\.po$/s%.*/%%p"
43 COMMAND awk "{printf $1\";\"}"
44 OUTPUT_VARIABLE TRANSLATION_SET_CONTENT
46 MESSAGE( STATUS "Translations: ${TRANSLATION_SET_CONTENT}" )
48 # Create 'LANG.po's from po.tar.bz2
50 OUTPUT ${TRANSLATION_SET_CONTENT}
51 COMMAND tar xfj ${CMAKE_CURRENT_SOURCE_DIR}/${TRANSLATION_SET}
52 COMMAND sed -i '/^msgid/s/do not forbid installation of %s/remove lock to allow installation of %s/' *.po
53 COMMAND sed -i '/^msgid/s/do not keep %s installed/remove lock to allow removal of %s/' *.po
54 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${TRANSLATION_SET}
57 # LANG.po ->msgfmt-> LANG.gmo
59 FOREACH( _currentPoFile ${TRANSLATION_SET_CONTENT} )
61 GET_FILENAME_COMPONENT( _lang ${_currentPoFile} NAME_WE )
62 SET( _gmoFile "${_lang}.gmo" )
63 SET( _gmoFiles ${_gmoFiles} ${_gmoFile} )
67 COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_currentPoFile}
68 DEPENDS ${_currentPoFile}
72 FILES ${CMAKE_CURRENT_BINARY_DIR}/${_gmoFile}
73 DESTINATION share/locale/${_lang}/LC_MESSAGES
74 RENAME ${_translation_set_basename}.mo
77 # the docs claim it can handle a list, but
78 SET_DIRECTORY_PROPERTIES( PROPERTIES
79 ADDITIONAL_MAKE_CLEAN_FILES ${_currentPoFile}
80 ADDITIONAL_MAKE_CLEAN_FILES ${_gmoFile}
83 ENDFOREACH( _currentPoFile )
85 # build all .gmo files
91 ENDMACRO( GETTEXT_CREATE_TARBALL_TRANSLATIONS )
94 # Macro to be called if .po files are part of the source tree.
96 MACRO(GETTEXT_CREATE_TRANSLATIONS _moBasename _firstPoFile)
101 IF(${_firstPoFile} STREQUAL "ALL")
104 ENDIF(${_firstPoFile} STREQUAL "ALL")
106 FOREACH (_currentPoFile ${_firstPoFile} ${ARGN})
107 GET_FILENAME_COMPONENT(_absFile ${_currentPoFile} ABSOLUTE)
108 GET_FILENAME_COMPONENT(_abs_PATH ${_absFile} PATH)
109 GET_FILENAME_COMPONENT(_lang ${_absFile} NAME_WE)
110 SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo)
114 COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_absFile}
118 INSTALL(FILES ${_gmoFile} DESTINATION share/locale/${_lang}/LC_MESSAGES RENAME ${_moBasename}.mo)
119 SET(_gmoFiles ${_gmoFiles} ${_gmoFile})
121 ENDFOREACH (_currentPoFile )
123 ADD_CUSTOM_TARGET(translations ${_addToAll} DEPENDS ${_gmoFiles})
125 ENDMACRO(GETTEXT_CREATE_TRANSLATIONS )
127 IF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )
128 SET(GETTEXT_FOUND TRUE)
129 ELSE (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )
130 SET(GETTEXT_FOUND FALSE)
131 IF (GetText_REQUIRED)
132 MESSAGE(FATAL_ERROR "GetText not found")
133 ENDIF (GetText_REQUIRED)
134 ENDIF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )