summaryrefslogtreecommitdiff
path: root/po/CMakeLists.txt
blob: 4028ad6749ed7060227aaee636b9fa9884def777 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#
# Copyright (C) 2003-2019 Sébastien Helleu <flashcode@flashtux.org>
#
# This file is part of WeeChat, the extensible chat client.
#
# WeeChat is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# WeeChat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with WeeChat.  If not, see <https://www.gnu.org/licenses/>.
#

set(PO_FILES
  cs.po
  de.po
  es.po
  fr.po
  hu.po
  it.po
  ja.po
  pl.po
  pt.po
  pt_BR.po
  ru.po
  tr.po
  )

set(BUGS_ADDRESS "flashcode@flashtux.org")
set(POT_FILE ${PROJECT_NAME}.pot)
set(POT_FILE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${POT_FILE})

include(srcfiles.cmake)

# Looking for xgettext, msgmerge and msgfmt
find_program(XGETTEXT_EXECUTABLE xgettext)
find_program(MSGMERGE_EXECUTABLE msgmerge)
find_program(MSGFMT_EXECUTABLE msgfmt)

if(XGETTEXT_EXECUTABLE AND MSGMERGE_EXECUTABLE AND MSGFMT_EXECUTABLE)

  # Create PO template file weechat.pot
  set(SRC_FILES)
  set(POT_DEPENDS)

  foreach(srcfile ${WEECHAT_SOURCES})
    set(SRC_FILES ${SRC_FILES} ${srcfile})
    set(POT_DEPENDS ${POT_DEPENDS} ${CMAKE_SOURCE_DIR}/${srcfile})
  endforeach(srcfile ${WEECHAT_SOURCES})

  add_custom_command(
    OUTPUT ${POT_FILE_PATH}
    COMMAND ${XGETTEXT_EXECUTABLE}
    ARGS -o ${POT_FILE_PATH} --add-comments='TRANSLATORS:' --keyword='_' --keyword='weechat_gettext' --keyword='N_' --keyword='NG_:1,2' --keyword='weechat_ngettext:1,2' --no-location --from-code=UTF-8 --directory=${CMAKE_SOURCE_DIR} --package-name='WeeChat' --package-version=${VERSION} --msgid-bugs-address=${BUGS_ADDRESS} --copyright-holder='NAME' ${SRC_FILES}
    DEPENDS ${POT_DEPENDS}
    COMMENT "Generating ${POT_FILE}"
    )

  set(GMO_FILES)
  set(UPDATE_PO_TARGETS)
  foreach(pofile ${PO_FILES})
    get_filename_component(polang ${pofile} NAME_WE)

    # Compile .po files in build directory (to binary .gmo files)
    set(gmofile ${CMAKE_CURRENT_BINARY_DIR}/${polang}.gmo)
    add_custom_command(
      OUTPUT ${gmofile}
      COMMAND ${MSGMERGE_EXECUTABLE} ARGS --quiet -o ${CMAKE_CURRENT_BINARY_DIR}/${pofile} ${CMAKE_CURRENT_SOURCE_DIR}/${pofile} ${POT_FILE_PATH}
      COMMAND ${MSGFMT_EXECUTABLE} ARGS -o ${gmofile} ${CMAKE_CURRENT_BINARY_DIR}/${pofile}
      COMMAND ${MSGFMT_EXECUTABLE} ARGS -c --statistics --verbose --output-file=/dev/null ${CMAKE_CURRENT_BINARY_DIR}/${pofile}
      DEPENDS ${POT_FILE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/${pofile}
      COMMENT "Compiling ${polang}.po"
      )

    # Update .po files in source directory (if needed)
    add_custom_target(
      update-${pofile}
      COMMAND ${MSGMERGE_EXECUTABLE} --quiet --update --backup=none ${CMAKE_CURRENT_SOURCE_DIR}/${pofile} ${POT_FILE_PATH}
      COMMENT "Updating ${polang}.po"
      )
    set(UPDATE_PO_TARGETS ${UPDATE_PO_TARGETS} update-${pofile})

    install(FILES ${gmofile} DESTINATION ${LOCALEDIR}/${polang}/LC_MESSAGES RENAME ${PROJECT_NAME}.mo)
    set(GMO_FILES ${GMO_FILES} ${gmofile})
  endforeach(pofile ${PO_FILES})

  add_custom_target(translations ALL DEPENDS ${GMO_FILES})

  # Update weechat.pot in source directory (if needed)
  add_custom_target(
    update-${POT_FILE}
    COMMAND ${MSGMERGE_EXECUTABLE} --quiet --update --backup=none ${CMAKE_CURRENT_SOURCE_DIR}/${POT_FILE} ${POT_FILE_PATH}
    COMMENT "Updating ${POT_FILE}"
    )

  # Update all .po and weechat.pot in source directory (if needed)
  add_custom_target(update-po DEPENDS update-${POT_FILE} ${UPDATE_PO_TARGETS})

endif()