Update PO files.
[tails.git] / refresh-translations
blob510372b7c2a161aee79b265c1a607a9939b2ec46
1 #! /bin/sh
3 set -e
4 set -u
6 PERL_PROGS="/usr/local/bin/tails-security-check \
7 /usr/local/lib/tails-htp-notify-user \
8 /usr/local/lib/tails-virt-notify-user"
9 PYTHON_PROGS="/etc/whisperback/config.py \
10 /usr/local/bin/tails-about \
11 /usr/local/bin/tails-screen-locker \
12 /usr/local/sbin/tails-additional-software"
13 SHELL_PROGS="/etc/NetworkManager/dispatcher.d/60-tor-ready.sh \
14 /usr/local/bin/electrum \
15 /usr/local/bin/keepassx \
16 /usr/local/bin/tails-upgrade-frontend-wrapper \
17 /usr/local/lib/tails-spoof-mac \
18 /usr/local/bin/tor-browser \
19 /usr/local/sbin/unsafe-browser"
20 JAVASCRIPT_PROGS=" \
21 /usr/share/gnome-shell/extensions/status-menu-helper@tails.boum.org/extension.js \
22 /usr/share/gnome-shell/extensions/torstatus@tails.boum.org/extension.js \
25 LOCALE_BASEDIR=config/chroot_local-includes/usr/share/locale
27 ### External libraries
29 . config/chroot_local-includes/usr/local/lib/tails-shell-library/common.sh
30 . config/chroot_local-includes/usr/local/lib/tails-shell-library/po.sh
32 ### Functions
34 normalize_pot () {
35 sed --regexp-extended \
36 -i 's@^"Content-Type: text/plain; charset=CHARSET\\n"@"Content-Type: text/plain; charset=UTF-8\\n"@' \
37 "${@}"
40 prog_potfile () {
41 prog=$1
43 progpath="config/chroot_local-includes$prog"
44 case $prog in
45 /usr/share/gnome-shell/extensions/status-menu-helper@tails.boum.org/extension.js)
46 domain=status-menu-helper-extension.js
49 domain=$(basename $prog)
51 esac
52 echo "tmp/pot/${domain}.pot"
55 create_pot () {
56 prog=$1
57 proglang=$2
58 progpath="config/chroot_local-includes${prog}"
59 if [ -e "${progpath}" ]; then
60 pot="$(prog_potfile "${prog}")"
61 mkdir -p "$(dirname ${pot})"
62 xgettext --language="${proglang}" --from-code=UTF-8 \
63 -o "${pot}" "${progpath}"
64 normalize_pot "${pot}"
65 else
66 echo "error: We are supposed to create a POT file for '${prog}'" \
67 "but '${progpath}' does not exist"
68 exit 1
72 po_file () {
73 locale=$1
75 echo "po/${locale}.po"
78 mo_file () {
79 locale=$1
81 echo "${LOCALE_BASEDIR}/${locale}/LC_MESSAGES/tails.mo"
84 refresh_mo () {
85 for locale in "$@" ; do
86 po=$(po_file $locale)
87 mo=$(mo_file $locale)
88 mkdir -p $(dirname "$mo")
89 msgfmt -o "${mo}" "${po}"
90 done
93 no_left_out_files () {
94 (cd po && intltool-update --maintain)
95 [ ! -e po/missing ] || return 1
96 return 0
99 intltool_update_pot () {
101 cd po
102 cp -a tails.pot tails.pot.orig
103 intltool-update --pot --gettext-package=tails
104 normalize_pot tails.pot tails.pot.orig
106 if [ "${FORCE:-}" = yes ]; then
107 echo "Force-updating 'tails.pot'."
108 rm tails.pot.orig
109 elif diff_without_pot_creation_date_and_comments -q tails.pot.orig tails.pot; then
110 echo "Only header or comment changes in tails.pot: keeping the old one"
111 mv tails.pot.orig tails.pot
112 else
113 echo "Real changes in tails.pot: switching to the updated one"
114 rm tails.pot.orig
119 intltool_merge_desktop () {
120 extract_from_file_between_markers po/POTFILES.in \
121 '^# Files updated by intltool-update --desktop-style' '^$' \
122 | while read infile ; do
123 intltool-merge --quiet --desktop-style --utf8 \
124 po "$infile" "${infile%.in}"
125 done
128 intltool_merge_xml () {
129 extract_from_file_between_markers po/POTFILES.in \
130 '^# Files updated by intltool-update --xml-style' '^$' \
131 | while read infile ; do
132 intltool-merge --quiet --xml-style --utf8 \
133 po "$infile" "${infile%.in}"
134 done
137 ### Main
139 FORCE=no
140 KEEP_TMP_POT=no
141 while [ -n "${@:-}" ]; do
142 case "${1:-}" in
143 '--force')
144 FORCE=yes
146 '--keep-tmp-pot')
147 KEEP_TMP_POT=yes
150 echo "Unknown option: ${1}"
151 exit 1
153 esac
154 shift
155 done
157 # Schedule clean up
158 trap "rm -fr po/*.new po/*.orig ; [ "$KEEP_TMP_POT" = yes ] || rm -fr tmp/pot" EXIT
160 # Update POT files
161 mkdir -p tmp/pot
162 for prog in $PERL_PROGS ; do create_pot $prog Perl ; done
163 for prog in $PYTHON_PROGS ; do create_pot $prog Python ; done
164 for prog in $SHELL_PROGS ; do create_pot $prog Shell ; done
165 for prog in $JAVASCRIPT_PROGS ; do create_pot $prog JavaScript ; done
166 intltool_update_pot
168 # If left out files are detected, intltool-update --maintain writes
169 # them to po/missing.
170 no_left_out_files || exit 3
172 # Update PO files
173 intltool_update_po $(po_languages)
175 # Update files that are actually used at runtime
176 refresh_mo $(po_languages)
177 intltool_merge_desktop
178 intltool_merge_xml
179 chmod +x config/chroot_local-includes/etc/skel/Desktop/*.desktop