summaryrefslogtreecommitdiff
path: root/po/CMakeLists.txt
blob: f2dd8ae5c59bc6333f05691393113238d4dfc8c1 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
# Copyright © 2004-2013  Roger Leigh <rleigh@debian.org>
#
# schroot 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.
#
# schroot 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 this program.  If not, see
# <http://www.gnu.org/licenses/>.
#
#####################################################################

if(BUILD_NLS)

  set(domain schroot)
  set(xgettext_options --keyword=_ --keyword=N_ --from-code=UTF-8
      --boost --no-location)
  set(copyright_holder "Roger Leigh <rleigh@debian.org>")
  set(bug_address "Roger Leigh <rleigh@debian.org>")

  file(READ LINGUAS languages)
  string(REGEX REPLACE "\n" ";" languages "${languages}")
  foreach(lang ${languages})
    set(po_files ${po_files} "${CMAKE_CURRENT_SOURCE_DIR}/${lang}.po")
  endforeach(lang)

  file(READ ${CMAKE_CURRENT_SOURCE_DIR}/POTFILES.in potfiles)
  string(REGEX REPLACE "\n" ";" potfiles "${potfiles}")
  file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/POTFILES)
  foreach(file ${potfiles})
    set(translated_files ${translated_files} "${PROJECT_SOURCE_DIR}/${file}")
  endforeach(file ${potfiles})

  foreach(file ${translated_files})
    if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/POTFILES)
      file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/POTFILES "${file}\n")
    else(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/POTFILES)
      file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/POTFILES "${file}\n")
    endif(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/POTFILES)
  endforeach(file ${translated_files})

  # xgettext creates schroot.pot
  if(GIT_RELEASE_ENABLE)
    # Always update potfile when dependencies change.  Don't change
    # the date in the pot file, since this dirties the source
    # directory, but do allow any other change.
    message("grep '^\"POT-Creation-Date: ' '${CMAKE_CURRENT_SOURCE_DIR}/${domain}.pot' | sed -e 's;^\"POT-Creation-Date: \\(.*\\)\\\\n\";\\1;'")
    execute_process(COMMAND sh -c "grep '^\"POT-Creation-Date: ' '${CMAKE_CURRENT_SOURCE_DIR}/${domain}.pot' | sed -e 's;^\"POT-Creation-Date: \\(.*\\)\\\\n\";\\1;'"
                    OUTPUT_VARIABLE pot_date
                    RESULT_VARIABLE grep_pot_status
                    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
    string(REGEX REPLACE "\n" "" pot_date "${pot_date}")
    add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${domain}.pot"
                       COMMAND xgettext --default-domain=${domain} --add-comments=TRANSLATORS:
                         ${xgettext_options} --files-from "${CMAKE_CURRENT_BINARY_DIR}/POTFILES"
                         --copyright-holder=${copyright_holder}
                         --msgid-bugs-address=${bug_address}
                         -d "${domain}" -p "${CMAKE_CURRENT_SOURCE_DIR}"
                       COMMAND ${CMAKE_COMMAND} -E rename "${CMAKE_CURRENT_SOURCE_DIR}/${domain}.po" "${CMAKE_CURRENT_SOURCE_DIR}/${domain}.pot"
                       COMMAND sed -i -e 's;^\"POT-Creation-Date: \\(.*\\)\\\\n\";\"POT-Creation-Date: ${pot_date}\\\\n\";' "${CMAKE_CURRENT_SOURCE_DIR}/${domain}.pot"
                       DEPENDS ${translated_files}
                       VERBATIM)
    add_custom_target(update-pot DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${domain}.pot")
  else(GIT_RELEASE_ENABLE)
    # Only update potfile manually
    add_custom_target(update-pot
                      COMMAND xgettext --default-domain=${domain} --add-comments=TRANSLATORS:
                        ${xgettext_options} --files-from "${CMAKE_CURRENT_BINARY_DIR}/POTFILES"
                        --copyright-holder=${copyright_holder}
                        --msgid-bugs-address=${bug_address}
                        -d "${domain}" -p "${CMAKE_CURRENT_SOURCE_DIR}"
                      COMMAND ${CMAKE_COMMAND} -E rename "${CMAKE_CURRENT_SOURCE_DIR}/${domain}.po" "${CMAKE_CURRENT_SOURCE_DIR}/${domain}.pot"
                      DEPENDS ${translated_files}
                      VERBATIM)
  endif(GIT_RELEASE_ENABLE)

  # msgmerge --update
  foreach(pofile ${po_files})
    add_custom_command(OUTPUT "${pofile}"
                       COMMAND msgmerge --update "${pofile}"
                         "${CMAKE_CURRENT_SOURCE_DIR}/${domain}.pot"
                       COMMAND touch "${pofile}"
                       DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${domain}.pot"
                       VERBATIM)
  endforeach(pofile)
  add_custom_target(update-po DEPENDS ${po_files})

  # msgfmt
  foreach(lang ${languages})
    add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo"
                       COMMAND ${CMAKE_COMMAND} -E remove "${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo"
                       COMMAND msgfmt -c --statistics -o "${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo"
                         "${CMAKE_CURRENT_SOURCE_DIR}/${lang}.po"
                       COMMAND touch "${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo"
                       DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${lang}.po"
                       VERBATIM)
    install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo"
            DESTINATION "${SCHROOT_LOCALE_DIR}/${lang}/LC_MESSAGES"
            RENAME "${domain}.mo")
    set(gmo_files ${gmo_files} "${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo")
  endforeach(lang)

if(GIT_RELEASE_ENABLE)
  add_dependencies(git-release update-pot update-po)
endif(GIT_RELEASE_ENABLE)

  add_custom_target(update-gmo ALL DEPENDS ${gmo_files})

  add_custom_target(po-notify
                    COMMAND podebconf-report-po --call --withtranslators --noforce --podir=${CMAKE_CURRENT_SOURCE_DIR})

endif(BUILD_NLS)