1#############################################################################
2##    Kwave                - cmake/KwaveL10N.cmake l10n support
3##                           -------------------
4##    begin                : Sat Sep 13 2008
5##    copyright            : (C) 2008 by Thomas Eschenbacher
6##    email                : Thomas.Eschenbacher@gmx.de
7#############################################################################
8#
9#############################################################################
10#                                                                           #
11# Redistribution and use in source and binary forms, with or without        #
12# modification, are permitted provided that the following conditions        #
13# are met:                                                                  #
14#                                                                           #
15# 1. Redistributions of source code must retain the above copyright         #
16#    notice, this list of conditions and the following disclaimer.          #
17# 2. Redistributions in binary form must reproduce the above copyright      #
18#    notice, this list of conditions and the following disclaimer in the    #
19#    documentation and/or other materials provided with the distribution.   #
20#                                                                           #
21# For details see the accompanying cmake/COPYING-CMAKE-SCRIPTS file.        #
22#                                                                           #
23#############################################################################
24
25FIND_REQUIRED_PROGRAM(FIND_EXECUTABLE find)
26FIND_REQUIRED_PROGRAM(MSGCAT_EXECUTABLE msgcat)
27FIND_REQUIRED_PROGRAM(XGETTEXT_EXECUTABLE xgettext)
28FIND_REQUIRED_PROGRAM(MSGMERGE_EXECUTABLE msgmerge)
29FIND_REQUIRED_PROGRAM(MSGFMT_EXECUTABLE msgfmt)
30
31SET(PO_SRC_DIR "${CMAKE_SOURCE_DIR}/po")
32SET(PO_BIN_DIR "${CMAKE_BINARY_DIR}/po")
33
34#############################################################################
35### get environment variable LINGUAS, default to all languages            ###
36
37SET(LINGUAS "$ENV{LINGUAS}")
38STRING(REGEX REPLACE "[ \t]+" \; OUTPUT "${LINGUAS}")
39SEPARATE_ARGUMENTS(LINGUAS)
40IF ("${LINGUAS}" STREQUAL "")
41    SET(LINGUAS "*")
42ENDIF ("${LINGUAS}" STREQUAL "")
43
44#############################################################################
45### checks whether a language has been requested per configuration       ###
46
47MACRO(CHECK_LANG _lang _result)
48    # take only languages that have been requested
49    SET(${_result} TRUE)
50    IF (NOT "${LINGUAS}" STREQUAL "*")
51	LIST(FIND LINGUAS "${${_lang}}" _found)
52	IF (_found LESS 0)
53	    SET(${_result} FALSE)
54	ENDIF (_found LESS 0)
55    ENDIF (NOT "${LINGUAS}" STREQUAL "*")
56ENDMACRO(CHECK_LANG _lang _result)
57
58#############################################################################
59### find out which po files exist                                        ###
60
61FILE(GLOB _existing_po_files "${PO_SRC_DIR}/*.po")
62FOREACH(_po_file ${_existing_po_files})
63    GET_FILENAME_COMPONENT(_lang "${_po_file}" NAME_WE)
64
65    CHECK_LANG(_lang _take_it)
66    IF (_take_it)
67	LIST(APPEND KWAVE_BUILD_LINGUAS "${_lang}")
68	LIST(APPEND _po_files "${_po_file}")
69	MESSAGE(STATUS "Enabled GUI translation for ${_lang}")
70
71	# handle generation and installation of the message catalog (gmo)
72	SET(_gmo_file ${PO_BIN_DIR}/${_lang}.gmo)
73
74	ADD_CUSTOM_COMMAND(
75	    OUTPUT ${_gmo_file}
76	    COMMAND ${CMAKE_COMMAND} -E make_directory ${PO_BIN_DIR}
77	    COMMAND ${MSGFMT_EXECUTABLE} -o ${_gmo_file} ${_po_file}
78	    DEPENDS ${_po_file}
79	)
80
81	INSTALL(
82	    FILES ${_gmo_file}
83	    DESTINATION ${LOCALE_INSTALL_DIR}/${_lang}/LC_MESSAGES
84	    RENAME kwave.mo
85	)
86	SET(_gmo_files ${_gmo_files} ${_gmo_file})
87
88    ENDIF (_take_it)
89ENDFOREACH(_po_file ${_existing_po_files})
90
91#############################################################################
92### update the local copy of the translations with files from kde svn     ###
93
94ADD_CUSTOM_TARGET(update-translations
95    COMMAND ${CMAKE_SOURCE_DIR}/bin/svn-update-l10n.sh "${CMAKE_SOURCE_DIR}"
96)
97
98#############################################################################
99### processing of GUI translations if found                               ###
100
101IF (NOT "${KWAVE_BUILD_LINGUAS}" STREQUAL "")
102
103    IF ("${LINGUAS}" STREQUAL "*")
104	MESSAGE(STATUS "LINGUAS not set, building for all supported languages")
105    ENDIF ("${LINGUAS}" STREQUAL "*")
106
107    IF (_existing_po_files)
108
109	# build target "package-messages"
110	ADD_CUSTOM_TARGET(package-messages ALL DEPENDS ${_gmo_files} )
111
112	SET_DIRECTORY_PROPERTIES(PROPERTIES
113	    ADDITIONAL_MAKE_CLEAN_FILES
114	    "${CMAKE_BINARY_DIR}/po"
115	)
116    ENDIF (_existing_po_files)
117
118ELSE (NOT "${KWAVE_BUILD_LINGUAS}" STREQUAL "")
119
120    MESSAGE(STATUS "Found no suitable language to build for")
121
122ENDIF (NOT "${KWAVE_BUILD_LINGUAS}" STREQUAL "")
123
124#############################################################################
125### show the progress of translations                                     ###
126
127ADD_CUSTOM_TARGET(msgstats
128    COMMAND ${CMAKE_SOURCE_DIR}/bin/msgstats.pl ${CMAKE_SOURCE_DIR}
129)
130
131#############################################################################
132#############################################################################
133