1 # This file is part of LyX, the document processor.
2 # Licence details can be found in the file COPYING.
4 # Copyright (c) 2008-2011 Peter Kümmel, <syntheticpp@gmx.net>
5 # Copyright (c) 2008-2011 Kornel Benko, <Kornel.Benko@berlin.de>
10 include_directories(${TOP_SRC_DIR}/po)
12 SET(_lyxname ${PACKAGE})
14 macro(add_gettext_python _par _dir)
17 file(GLOB _s1 ${TOP_SRC_DIR}/${_dir}/${_arg})
19 list(APPEND _sources ${_s1})
21 if (${_par} MATCHES "layouttranslations")
22 SET(_dst "${CMAKE_CURRENT_BINARY_DIR}/${_par}")
24 SET(_dst "${CMAKE_CURRENT_BINARY_DIR}/${_par}_l10n.pot")
26 SET(_tmp_src_files "${CMAKE_CURRENT_BINARY_DIR}/${_par}_tmp_files")
27 SET(_src_files "${CMAKE_CURRENT_BINARY_DIR}/${_par}_files")
28 file(WRITE ${_tmp_src_files} "")
29 foreach(_s ${_sources})
30 FILE(APPEND ${_tmp_src_files} "${_s}\n")
32 if(${_par} MATCHES "^\(.*\)_[0-9]+$")
33 set(_par1 ${CMAKE_MATCH_1})
39 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_tmp_src_files} ${_src_files}
40 DEPENDS ${_tmp_src_files}
42 if (${_par} MATCHES "layouttranslations")
46 COMMAND ${CMAKE_COMMAND} -E copy_if_different "${TOP_SRC_DIR}/lib/layouttranslations" "${_dst}"
47 COMMAND ${LYX_PYTHON_EXECUTABLE}
48 ARGS "${TOP_SRC_DIR}/po/lyx_pot.py" -b "${TOP_SRC_DIR}" -o "${_dst}" -t ${_par1} "--src_file=${_src_files}"
49 COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_dst}" "${TOP_SRC_DIR}/lib/layouttranslations"
50 DEPENDS ${_sources} ${_src_files} "${TOP_SRC_DIR}/lib/layouttranslations"
51 COMMENT "${LYX_PYTHON_EXECUTABLE} ${TOP_SRC_DIR}/po/lyx_pot.py -b ${TOP_SRC_DIR} -o ${_dst} -t ${_par1} --src_file=${_src_files}"
53 ADD_CUSTOM_TARGET(layouttranslations1 DEPENDS "${_dst}")
54 set_target_properties(layouttranslations1 PROPERTIES FOLDER "i18n")
55 if (LYX_DATA_SUBDIR STREQUAL "")
56 install(FILES "${TOP_SRC_DIR}/lib/layouttranslations" DESTINATION .)
58 install(FILES "${TOP_SRC_DIR}/lib/layouttranslations" DESTINATION ${LYX_DATA_SUBDIR})
64 COMMAND ${LYX_PYTHON_EXECUTABLE}
65 ARGS "${TOP_SRC_DIR}/po/lyx_pot.py" -b "${TOP_SRC_DIR}" -o "${_dst}" -t ${_par1} "--src_file=${_src_files}"
66 DEPENDS ${_sources} ${_src_files}
67 COMMENT "${LYX_PYTHON_EXECUTABLE} ${TOP_SRC_DIR}/po/lyx_pot.py -b ${TOP_SRC_DIR} -o ${_dst} -t ${_par1} --src_file=${_src_files}"
69 LIST(APPEND _py_sources "${_dst}")
71 SET_SOURCE_FILES_PROPERTIES("${_dst}" GENERATED)
72 SET_SOURCE_FILES_PROPERTIES("${_src_files}" GENERATED)
73 endmacro(add_gettext_python)
75 SET_SOURCE_FILES_PROPERTIES("${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot" GENERATED)
76 SET_SOURCE_FILES_PROPERTIES("${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt.pot" GENERATED)
77 SET_SOURCE_FILES_PROPERTIES("${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot" GENERATED)
79 add_gettext_python(qt4 src/frontends/qt4/ui *.ui)
80 add_gettext_python(layouts lib/layouts *.layout *.inc *.module)
81 add_gettext_python(languages lib languages)
82 add_gettext_python(latexfonts lib latexfonts)
83 add_gettext_python(encodings lib encodings)
84 add_gettext_python(ui lib/ui *.ui *.inc)
85 add_gettext_python(external lib external_templates)
86 add_gettext_python(formats lib configure.py)
87 add_gettext_python(layouttranslations lib/layouts *.layout *.inc *.module)
90 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot"
91 COMMAND ${LYX_PYTHON_EXECUTABLE}
92 ARGS "${TOP_CMAKE_PATH}/po/cat.py" ${_py_sources} > "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat_tmp.pot"
93 COMMAND ${LYX_PYTHON_EXECUTABLE}
94 ARGS "${TOP_CMAKE_PATH}/po/dos2unix.py" "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat_tmp.pot"
95 COMMAND ${CMAKE_COMMAND} -E copy_if_different
96 "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat_tmp.pot" "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot"
97 DEPENDS ${_py_sources}
101 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt.pot"
102 COMMAND ${GETTEXT_MSGUNIQ_EXECUTABLE}
103 ARGS -o "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt_tmp.pot" "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot"
104 COMMAND ${CMAKE_COMMAND} -E copy_if_different
105 "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt_tmp.pot" "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt.pot"
106 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot"
111 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in.tmp "")
112 file(GLOB_RECURSE _tmp_potfiles RELATIVE ${TOP_SRC_DIR}/ ${TOP_SRC_DIR}/src/*.h ${TOP_SRC_DIR}/src/*.cpp ${TOP_SRC_DIR}/src/*.cpp.in)
113 list(SORT _tmp_potfiles)
114 # list(REMOVE_ITEM _tmp_potfiles src/support/Package.cpp)
116 foreach(_f ${_tmp_potfiles})
117 # we don't need to select only relevant files because the outcome of xgettext
118 # will stay the same.
119 # Relevant files are files containing the string '_(".*")'
120 LIST(APPEND _potfiles_dep "${TOP_SRC_DIR}/${_f}")
121 file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in.tmp "${_f}\n")
125 COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in.tmp" "${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in"
129 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot"
130 COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt.pot" "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot"
131 COMMAND ${GETTEXT_XGETTEXT_EXECUTABLE}
133 --default-domain=${_lyxname} --directory=${TOP_SRC_DIR}
134 --add-comments=TRANSLATORS:
135 --language=C++ --join-existing --keyword=_ --keyword=N_ --keyword=B_ --keyword=qt_
136 --files-from=${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in
137 --copyright-holder="LyX Developers" --msgid-bugs-address=lyx-devel@lists.lyx.org
138 -o "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot"
139 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt.pot" ${_potfiles_dep}
143 # We have to copy the po-files first,
144 # otherwise they would be modified (inside the macro GETTEXT_CREATE_TRANSLATIONS())
145 # This makes the "git pull" on po-files work again
146 file(GLOB LYX_BASE_PO_FILES RELATIVE ${TOP_SRC_DIR}/po ${TOP_SRC_DIR}/po/*.po)
147 list(SORT LYX_BASE_PO_FILES)
149 SET(LYX_UPDATED_PO_FILES)
150 SET(LYX_DEST_PO ${TOP_SRC_DIR}/po)
152 set(CONFIGURED_LANGUAGES) # from file LINGUAS
153 set(INSTALLED_LANGUAGES) # from names of existing po-files
155 file(STRINGS "${TOP_SRC_DIR}/po/LINGUAS" _lang_lines)
156 foreach(_c_l ${_lang_lines})
157 if(NOT _c_l MATCHES "^#.*")
158 string(REPLACE " " ";" _c_l ${_c_l}) #Split ${_c_l}
159 list(APPEND CONFIGURED_LANGUAGES ${_c_l})
163 foreach(_pofile ${LYX_BASE_PO_FILES})
164 string(REGEX REPLACE "^(.*)\\.po$" "\\1" _inst_lng ${_pofile})
165 list(FIND CONFIGURED_LANGUAGES ${_inst_lng} _lng_idx)
166 if(_lng_idx GREATER -1)
167 list(APPEND INSTALLED_LANGUAGES ${_inst_lng})
170 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}
171 COMMAND ${CMAKE_COMMAND} -E copy ${TOP_SRC_DIR}/po/${_pofile} ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}
172 DEPENDS ${TOP_SRC_DIR}/po/${_pofile}
174 list(APPEND LYX_PO_FILES ${CMAKE_CURRENT_BINARY_DIR}/${_pofile})
177 FIND_PROGRAM(LYX_GITVERSION git)
178 set(LYX_UPDATED_GMO_FILES)
179 foreach(_gmo_base ${INSTALLED_LANGUAGES})
180 set(_gmo ${_gmo_base}.gmo)
181 set(_tobeupdated "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}.tobeupdated")
182 list(APPEND LYX_UPDATED_GMO_FILES "${_tobeupdated}")
185 OUTPUT "${_tobeupdated}"
186 COMMAND "${LYX_GITVERSION}" "status" "--porcelain" "${_gmo_base}.po" ">" "${_tobeupdated}"
187 COMMAND ${LYX_PYTHON_EXECUTABLE} "${TOP_CMAKE_PATH}/po/update-gmo.py"
189 "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}"
190 "${LYX_DEST_PO}/${_gmo}"
191 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
192 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}"
196 OUTPUT "${_tobeupdated}"
197 COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}" "${LYX_DEST_PO}/${_gmo}"
198 COMMAND ${CMAKE_COMMAND} -E touch "${_tobeupdated}"
199 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}"
204 set(LYX_UPDATED_PO_FILES)
205 foreach(_pofile ${LYX_BASE_PO_FILES})
208 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}.copied
209 COMMAND ${LYX_PYTHON_EXECUTABLE}
210 ARGS "${TOP_CMAKE_PATH}/po/unix2dos.py" "${CMAKE_CURRENT_BINARY_DIR}/${_pofile}"
211 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/${_pofile} ${LYX_DEST_PO}/${_pofile}
212 COMMAND ${CMAKE_COMMAND} -E touch ${_pofile}.copied
213 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}
217 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}.copied
218 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/${_pofile} ${LYX_DEST_PO}/${_pofile}
219 COMMAND ${CMAKE_COMMAND} -E touch ${_pofile}.copied
220 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}
223 list(APPEND LYX_UPDATED_PO_FILES ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}.copied)
226 if(LYX_CPACK OR LYX_INSTALL)
227 set(_addALLOption ALL)
229 GETTEXT_CREATE_TRANSLATIONS(${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot ${_addALLOption} ${LYX_PO_FILES})
231 # Create a new target to remerge po files
232 # ALL omitted here, to prevent from automatic creation
233 ADD_CUSTOM_TARGET(update-gmo DEPENDS ${LYX_UPDATED_GMO_FILES})
234 ADD_CUSTOM_TARGET(update-po DEPENDS ${LYX_UPDATED_PO_FILES} ${LYX_UPDATED_GMO_FILES})
235 set_target_properties(update-po update-gmo PROPERTIES FOLDER "i18n")
236 add_dependencies(update-po translations)