]> git.lyx.org Git - lyx.git/blob - development/cmake/modules/FindLyXGettext.cmake
French Additional manual, translation of chapter 4 up to sec. 4.3
[lyx.git] / development / cmake / modules / FindLyXGettext.cmake
1 # - Slightly modified Find GNU gettext tools
2 # This module looks for the GNU gettext tools. This module defines the 
3 # following values:
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.
7 #
8 # Additionally it provides the following macros:
9 # GETTEXT_CREATE_TRANSLATIONS ( outputFile [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.
14
15 set(hints HINTS "${GNUWIN32_DIR}/gettext-tools")
16 FIND_PROGRAM(GETTEXT_MSGMERGE_EXECUTABLE msgmerge ${hints})
17 FIND_PROGRAM(GETTEXT_MSGFMT_EXECUTABLE   msgfmt   ${hints})
18 FIND_PROGRAM(GETTEXT_XGETTEXT_EXECUTABLE xgettext ${hints})
19 FIND_PROGRAM(GETTEXT_MSGUNIQ_EXECUTABLE  msguniq  ${hints})
20 FIND_PROGRAM(GETTEXT_MSGCAT_EXECUTABLE  msgcat  ${hints})
21
22 MACRO(GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFile)
23
24    SET(_gmoFiles)
25    # remove only the last extension e.g
26    #    LyX2.0.pot ==> LyX2.0
27    # and not LyX2.0.pot ==> LyX2
28    # as it would be with NAME_WE
29    # GET_FILENAME_COMPONENT(_potBasename ${_potFile} NAME_WE)
30    GET_FILENAME_COMPONENT(_potname ${_potFile} NAME)
31    if (_potname MATCHES "^\(.+\)\\.[^\\.]+$")
32        set(_potBasename ${CMAKE_MATCH_1})
33    else()
34        set(_potBasename ${_potname})
35    endif()
36    GET_FILENAME_COMPONENT(_absPotFile ${_potFile} ABSOLUTE)
37
38    SET(_addToAll)
39    set(_firstArg)
40    IF(${_firstPoFile} STREQUAL "ALL")
41       SET(_addToAll "ALL")
42    else()
43       set(_firstArg ${_firstPoFile})
44    ENDIF(${_firstPoFile} STREQUAL "ALL")
45
46    get_locale_destination(LYX_LOCALEDIR)
47    FOREACH (_currentPoFile ${_firstArg} ${ARGN})
48       GET_FILENAME_COMPONENT(_absFile ${_currentPoFile} ABSOLUTE)
49       GET_FILENAME_COMPONENT(_abs_PATH ${_absFile} PATH)
50       GET_FILENAME_COMPONENT(_lang ${_absFile} NAME_WE)
51       SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo)
52
53       ADD_CUSTOM_COMMAND( 
54          OUTPUT ${_gmoFile} 
55          COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update --backup=none ${_absFile} ${_absPotFile}
56          COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -c --statistics -o ${_gmoFile}.1 ${_absFile}
57          COMMAND ${CMAKE_COMMAND} -E rename ${_gmoFile}.1 ${_gmoFile}
58          DEPENDS ${_absPotFile} ${_absFile}
59       )
60
61       INSTALL(FILES ${_gmoFile} DESTINATION ${LYX_LOCALEDIR}/${_lang}/LC_MESSAGES RENAME ${_potBasename}.mo)
62       SET(_gmoFiles ${_gmoFiles} ${_gmoFile})
63
64    ENDFOREACH (_currentPoFile )
65
66    ADD_CUSTOM_TARGET(translations ${_addToAll} DEPENDS ${_gmoFiles})
67    set_target_properties(translations PROPERTIES FOLDER "i18n")
68
69 ENDMACRO(GETTEXT_CREATE_TRANSLATIONS )
70
71 IF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )
72    SET(GETTEXT_FOUND TRUE)
73 ELSE (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )
74    SET(GETTEXT_FOUND FALSE)
75    IF (GetText_REQUIRED)
76       MESSAGE(FATAL_ERROR "GetText not found")
77    ENDIF (GetText_REQUIRED)
78 ENDIF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )
79
80 mark_as_advanced(GETTEXT_MSGMERGE_EXECUTABLE GETTEXT_MSGFMT_EXECUTABLE GETTEXT_XGETTEXT_EXECUTABLE GETTEXT_MSGUNIQ_EXECUTABLE GETTEXT_MSGCAT_EXECUTABLE)
81