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})
15 macro(add_gettext_python _par _dir)
18 file(GLOB _s1 ${TOP_SRC_DIR}/${_dir}/${_arg})
20 list(APPEND _sources ${_s1})
22 if (${_par} MATCHES "layouttranslations")
23 SET(_dst "${CMAKE_CURRENT_BINARY_DIR}/${_par}")
25 SET(_dst "${CMAKE_CURRENT_BINARY_DIR}/${_par}_l10n.pot")
27 SET(_tmp_src_files "${CMAKE_CURRENT_BINARY_DIR}/${_par}_tmp_files")
28 SET(_src_files "${CMAKE_CURRENT_BINARY_DIR}/${_par}_files")
29 file(WRITE ${_tmp_src_files} "")
30 foreach(_s ${_sources})
31 FILE(APPEND ${_tmp_src_files} "${_s}\n")
33 if(${_par} MATCHES "^\(.*\)_[0-9]+$")
34 set(_par1 ${CMAKE_MATCH_1})
40 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_tmp_src_files} ${_src_files}
41 DEPENDS ${_tmp_src_files}
43 if (${_par} MATCHES "layouttranslations")
44 # lyx_pot.py requires the module "polib" if using target layouttranslations1,
45 # so we have to check for it
46 find_python_module("polib")
47 if ("${LYX_PY_POLIB}" STREQUAL "")
48 message(STATUS "You will be unable to update layouttranslations file")
53 COMMAND ${CMAKE_COMMAND}
54 "-DTOP_SRC_DIR=${TOP_SRC_DIR}"
56 "-DLYX_PYTHON_EXECUTABLE=${LYX_PYTHON_EXECUTABLE}"
58 "-DSources=${_src_files}"
59 "-DLYX_PY_POLIB=${LYX_PY_POLIB}"
60 -P "${TOP_SRC_DIR}/po/CreateLayoutTranslations.cmake"
61 DEPENDS ${_sources} ${_src_files} "${TOP_SRC_DIR}/lib/layouttranslations"
62 COMMENT "${LYX_PYTHON_EXECUTABLE} ${TOP_SRC_DIR}/po/lyx_pot.py -b ${TOP_SRC_DIR} -o ${_dst} -t ${_par1} --src_file=${_src_files}"
64 ADD_CUSTOM_TARGET(layouttranslations1 DEPENDS "${_dst}")
65 set_target_properties(layouttranslations1 PROPERTIES FOLDER "i18n")
66 if (LYX_DATA_SUBDIR STREQUAL "")
67 install(FILES "${TOP_SRC_DIR}/lib/layouttranslations" DESTINATION .)
69 install(FILES "${TOP_SRC_DIR}/lib/layouttranslations" DESTINATION ${LYX_DATA_SUBDIR})
75 COMMAND ${LYX_PYTHON_EXECUTABLE}
76 ARGS "${TOP_SRC_DIR}/po/lyx_pot.py" -b "${TOP_SRC_DIR}" -o "${_dst}" -t ${_par1} "--src_file=${_src_files}"
77 DEPENDS ${_sources} ${_src_files}
78 COMMENT "${LYX_PYTHON_EXECUTABLE} ${TOP_SRC_DIR}/po/lyx_pot.py -b ${TOP_SRC_DIR} -o ${_dst} -t ${_par1} --src_file=${_src_files}"
80 LIST(APPEND _py_sources "${_dst}")
82 SET_SOURCE_FILES_PROPERTIES("${_dst}" GENERATED)
83 SET_SOURCE_FILES_PROPERTIES("${_src_files}" GENERATED)
84 endmacro(add_gettext_python)
86 SET_SOURCE_FILES_PROPERTIES("${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot" GENERATED)
87 SET_SOURCE_FILES_PROPERTIES("${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt.pot" GENERATED)
88 SET_SOURCE_FILES_PROPERTIES("${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot" GENERATED)
90 add_gettext_python(qt4 src/frontends/qt4/ui *.ui)
91 add_gettext_python(layouts lib layouts/*.layout layouts/*.inc layouts/*.module citeengines/*.citeengine)
92 add_gettext_python(languages lib languages)
93 add_gettext_python(latexfonts lib latexfonts)
94 add_gettext_python(encodings lib encodings)
95 add_gettext_python(ui lib/ui *.ui *.inc)
96 add_gettext_python(external lib/xtemplates *.xtemplate)
97 add_gettext_python(formats lib configure.py)
98 add_gettext_python(layouttranslations lib layouts/*.layout layouts/*.inc layouts/*.module citeengines/*.citeengines)
101 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot"
102 COMMAND ${LYX_PYTHON_EXECUTABLE}
103 ARGS "${TOP_CMAKE_PATH}/po/cat.py" ${_py_sources} > "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat_tmp.pot"
104 COMMAND ${CMAKE_COMMAND} -E copy_if_different
105 "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat_tmp.pot" "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot"
106 DEPENDS ${_py_sources}
110 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt.pot"
111 COMMAND ${GETTEXT_MSGUNIQ_EXECUTABLE}
112 ARGS -o "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt_tmp.pot" "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot"
113 COMMAND ${CMAKE_COMMAND} -E copy_if_different
114 "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt_tmp.pot" "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt.pot"
115 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.cat.pot"
120 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in.tmp "")
121 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)
122 list(SORT _tmp_potfiles)
123 # list(REMOVE_ITEM _tmp_potfiles src/support/Package.cpp)
125 foreach(_f ${_tmp_potfiles})
126 # we don't need to select only relevant files because the outcome of xgettext
127 # will stay the same.
128 # Relevant files are files containing the string '_(".*")'
129 LIST(APPEND _potfiles_dep "${TOP_SRC_DIR}/${_f}")
130 file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in.tmp "${_f}\n")
134 COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in.tmp" "${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in"
138 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot"
139 COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt.pot" "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot"
140 COMMAND ${GETTEXT_XGETTEXT_EXECUTABLE}
142 --default-domain=${_lyxname} --directory=${TOP_SRC_DIR}
143 --add-comments=TRANSLATORS:
144 --language=C++ --join-existing --keyword=_ --keyword=N_ --keyword=B_ --keyword=qt_
145 --files-from=${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in
146 --copyright-holder="LyX Developers" --msgid-bugs-address=lyx-devel@lists.lyx.org
147 -o "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot"
148 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.fmt.pot" ${_potfiles_dep}
152 # We have to copy the po-files first,
153 # otherwise they would be modified (inside the macro GETTEXT_CREATE_TRANSLATIONS())
154 # This makes the "git pull" on po-files work again
155 file(GLOB LYX_BASE_PO_FILES RELATIVE ${TOP_SRC_DIR}/po ${TOP_SRC_DIR}/po/*.po)
156 list(SORT LYX_BASE_PO_FILES)
158 SET(LYX_UPDATED_PO_FILES)
159 SET(LYX_DEST_PO ${TOP_SRC_DIR}/po)
161 set(CONFIGURED_LANGUAGES) # from file LINGUAS
162 set(INSTALLED_LANGUAGES) # from names of existing po-files
164 file(STRINGS "${TOP_SRC_DIR}/po/LINGUAS" _lang_lines)
165 foreach(_c_l ${_lang_lines})
166 if(NOT _c_l MATCHES "^#.*")
167 string(REPLACE " " ";" _c_l ${_c_l}) #Split ${_c_l}
168 list(APPEND CONFIGURED_LANGUAGES ${_c_l})
172 foreach(_pofile ${LYX_BASE_PO_FILES})
173 string(REGEX REPLACE "^(.*)\\.po$" "\\1" _inst_lng ${_pofile})
174 list(FIND CONFIGURED_LANGUAGES ${_inst_lng} _lng_idx)
175 if(_lng_idx GREATER -1)
176 list(APPEND INSTALLED_LANGUAGES ${_inst_lng})
179 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}
180 COMMAND ${CMAKE_COMMAND} -E copy ${TOP_SRC_DIR}/po/${_pofile} ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}
181 DEPENDS ${TOP_SRC_DIR}/po/${_pofile}
183 list(APPEND LYX_PO_FILES ${CMAKE_CURRENT_BINARY_DIR}/${_pofile})
186 FIND_PROGRAM(LYX_GITVERSION git)
187 set(LYX_UPDATED_GMO_FILES)
188 foreach(_gmo_base ${INSTALLED_LANGUAGES})
189 set(_gmo ${_gmo_base}.gmo)
190 set(_tobeupdated "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}.tobeupdated")
191 list(APPEND LYX_UPDATED_GMO_FILES "${_tobeupdated}")
194 OUTPUT "${_tobeupdated}"
195 COMMAND "${LYX_GITVERSION}" "status" "--porcelain" "${_gmo_base}.po" ">" "${_tobeupdated}"
196 COMMAND ${LYX_PYTHON_EXECUTABLE} "${TOP_CMAKE_PATH}/po/update-gmo.py"
198 "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}"
199 "${LYX_DEST_PO}/${_gmo}"
200 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
201 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}"
205 OUTPUT "${_tobeupdated}"
206 COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}" "${LYX_DEST_PO}/${_gmo}"
207 COMMAND ${CMAKE_COMMAND} -E touch "${_tobeupdated}"
208 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_gmo}"
213 set(LYX_UPDATED_PO_FILES)
214 foreach(_pofile ${LYX_BASE_PO_FILES})
217 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}.copied
218 COMMAND ${LYX_PYTHON_EXECUTABLE}
219 ARGS "${TOP_CMAKE_PATH}/po/unix2dos.py" "${CMAKE_CURRENT_BINARY_DIR}/${_pofile}"
220 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/${_pofile} ${LYX_DEST_PO}/${_pofile}
221 COMMAND ${CMAKE_COMMAND} -E touch ${_pofile}.copied
222 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}
226 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}.copied
227 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/${_pofile} ${LYX_DEST_PO}/${_pofile}
228 COMMAND ${CMAKE_COMMAND} -E touch ${_pofile}.copied
229 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}
232 list(APPEND LYX_UPDATED_PO_FILES ${CMAKE_CURRENT_BINARY_DIR}/${_pofile}.copied)
235 if(LYX_CPACK OR LYX_INSTALL)
236 set(_addALLOption ALL)
238 GETTEXT_CREATE_TRANSLATIONS(${CMAKE_CURRENT_BINARY_DIR}/${_lyxname}.pot ${_addALLOption} ${LYX_PO_FILES})
240 # Create a new target to remerge po files
241 # ALL omitted here, to prevent from automatic creation
242 ADD_CUSTOM_TARGET(update-gmo DEPENDS ${LYX_UPDATED_GMO_FILES})
243 ADD_CUSTOM_TARGET(update-po DEPENDS ${LYX_UPDATED_PO_FILES} ${LYX_UPDATED_GMO_FILES})
244 set_target_properties(update-po update-gmo PROPERTIES FOLDER "i18n")
245 add_dependencies(update-po translations)