Calendar: add FT sprint
[tails/test.git] / refresh-translations
blob121de63e2f56d454d14af7b904ba2c62de9cad2f
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 $(find \
10 config/chroot_local-includes/usr/src/iuk/bin \
11 config/chroot_local-includes/usr/src/persistence-setup/bin \
12 -type f \
13 | perl -p -E 's{^config/chroot_local-includes}{}' \
14 ) \
15 $(find \
16 config/chroot_local-includes/usr/src/iuk/lib \
17 config/chroot_local-includes/usr/src/perl5lib/lib \
18 config/chroot_local-includes/usr/src/persistence-setup/lib \
19 -type f -name *.pm \
20 | perl -p -E 's{^config/chroot_local-includes}{}' \
22 PYTHON_PROGS="/etc/whisperback/config.py \
23 /usr/local/bin/electrum \
24 /usr/local/bin/replace-su-with-sudo \
25 /usr/local/bin/tails-about \
26 /usr/local/bin/tails-additional-software-config \
27 /usr/local/bin/tails-screen-locker \
28 /usr/local/bin/tails-upgrade-frontend-wrapper \
29 /usr/local/lib/seahorse-tool-wrapper \
30 /usr/local/sbin/tails-additional-software \
31 /usr/lib/python3/dist-packages/tails_installer/creator.py \
32 /usr/lib/python3/dist-packages/tails_installer/gui.py \
33 /usr/lib/python3/dist-packages/tails_installer/source.py \
34 /usr/lib/python3/dist-packages/tails_installer/utils.py \
35 /usr/lib/python3/dist-packages/tailsgreeter/settings/persistence.py \
36 /usr/lib/python3/dist-packages/tailsgreeter/ui/add_settings_dialog.py \
37 /usr/lib/python3/dist-packages/tailsgreeter/ui/additional_settings.py \
38 /usr/lib/python3/dist-packages/tailsgreeter/ui/persistent_storage.py \
39 /usr/lib/python3/dist-packages/tailsgreeter/ui/region_settings.py \
40 /usr/lib/python3/dist-packages/unlock_veracrypt_volumes/volume.py \
41 /usr/lib/python3/dist-packages/unlock_veracrypt_volumes/volume_list.py \
42 /usr/lib/python3/dist-packages/unlock_veracrypt_volumes/volume_manager.py \
43 /usr/lib/python3/dist-packages/whisperBack/exceptions.py \
44 /usr/lib/python3/dist-packages/whisperBack/gui.py \
45 /usr/lib/python3/dist-packages/whisperBack/whisperback.py \
46 /usr/local/lib/tails-additional-software-notify \
47 /usr/local/sbin/tails-additional-software"
48 SHELL_PROGS="/etc/NetworkManager/dispatcher.d/60-tor-ready.sh \
49 /usr/local/bin/keepassxc \
50 /usr/local/lib/tails-spoof-mac \
51 /usr/local/bin/thunderbird \
52 /usr/local/bin/tor-browser \
53 /usr/local/sbin/unsafe-browser"
54 JAVASCRIPT_PROGS=" \
55 /usr/share/gnome-shell/extensions/status-menu-helper@tails.boum.org/extension.js \
56 /usr/share/gnome-shell/extensions/torstatus@tails.boum.org/extension.js \
58 GLADE_UI="\
59 /usr/share/tails/additional-software/configuration-window.ui \
62 LOCALE_BASEDIR=config/chroot_local-includes/usr/share/locale
64 ### External libraries
66 . config/chroot_local-includes/usr/local/lib/tails-shell-library/common.sh
67 . config/chroot_local-includes/usr/local/lib/tails-shell-library/po.sh
69 ### Functions
71 normalize_pot () {
72 sed --regexp-extended \
73 -i 's@^"Content-Type: text/plain; charset=CHARSET\\n"@"Content-Type: text/plain; charset=UTF-8\\n"@' \
74 "${@}"
77 prog_potfile () {
78 prog=$1
80 progpath="config/chroot_local-includes$prog"
81 case $prog in
82 /usr/share/gnome-shell/extensions/status-menu-helper@tails.boum.org/extension.js)
83 domain=status-menu-helper-extension.js
85 /usr/share/gnome-shell/extensions/torstatus@tails.boum.org/extension.js)
86 domain=torstatus-extension.js
88 /usr/lib/python3/dist-packages/unlock_veracrypt_volumes/*)
89 domain="unlock-veracrypt-volumes-$(basename "$prog")"
91 /usr/lib/python3/dist-packages/tailsgreeter/*)
92 domain="greeter-$(basename "$prog")"
94 /usr/lib/python*/dist-packages/tails_installer/*)
95 domain="installer-$(basename "$prog")"
97 /usr/lib/python3/dist-packages/whisperBack/*)
98 domain="whisperBack-$(basename "$prog")"
100 /usr/src/persistence-setup/lib/*)
101 domain="persistence-setup-$(basename "$prog")"
104 domain=$(basename $prog)
106 esac
107 echo "tmp/pot/${domain}.pot"
110 create_pot () {
111 prog=$1
112 proglang=$2
113 progpath="config/chroot_local-includes${prog}"
114 if [ -e "${progpath}" ]; then
115 pot="$(prog_potfile "${prog}")"
116 mkdir -p "$(dirname ${pot})"
117 case "$proglang" in
118 Perl)
119 # XXX: once we can assume libintl-perl 1.28+,
120 # generate this list of options with:
121 # perl -MLocale::TextDomain -E 'print Locale::TextDomain->options'
122 xgettext_args='--keyword'
123 xgettext_args="$xgettext_args --keyword=__"
124 xgettext_args="$xgettext_args --keyword='\$__'"
125 xgettext_args="$xgettext_args --keyword=__x"
126 xgettext_args="$xgettext_args --keyword=__n:1,2"
127 xgettext_args="$xgettext_args --keyword=__nx:1,2"
128 xgettext_args="$xgettext_args --keyword=__xn:1,2"
129 xgettext_args="$xgettext_args --keyword=__p:1c,2"
130 xgettext_args="$xgettext_args --keyword=__np:1c,2,3"
131 xgettext_args="$xgettext_args --keyword=__npx:1c,2,3"
132 xgettext_args="$xgettext_args --keyword=N__"
133 xgettext_args="$xgettext_args --keyword=N__n:1,2"
134 xgettext_args="$xgettext_args --keyword=N__p:1c,2"
135 xgettext_args="$xgettext_args --keyword=N__np:1c,2,3"
136 xgettext_args="$xgettext_args --keyword=%__'"
139 xgettext_args=
141 esac
142 xgettext --language="${proglang}" --from-code=UTF-8 \
143 $xgettext_args \
144 --add-comments="Translators:" -o "${pot}" "${progpath}"
145 if [ -f "${pot}" ]; then
146 normalize_pot "${pot}"
148 else
149 echo "error: We are supposed to create a POT file for '${prog}'" \
150 "but '${progpath}' does not exist"
151 exit 1
155 po_file () {
156 locale=$1
158 echo "po/${locale}.po"
161 mo_file () {
162 locale=$1
164 echo "${LOCALE_BASEDIR}/${locale}/LC_MESSAGES/tails.mo"
167 refresh_mo () {
168 for locale in "$@" ; do
169 po=$(po_file $locale)
170 mo=$(mo_file $locale)
171 mkdir -p $(dirname "$mo")
172 msgfmt --check -o "${mo}" "${po}"
173 done
176 no_left_out_files () {
177 (cd po && intltool-update --maintain)
178 [ ! -e po/missing ] || return 1
179 return 0
182 intltool_update_pot () {
184 cd po
185 cp -a tails.pot tails.pot.orig
186 intltool-update --pot --gettext-package=tails
187 normalize_pot tails.pot tails.pot.orig
189 if [ "${FORCE:-}" = yes ]; then
190 echo "Force-updating 'tails.pot'."
191 rm tails.pot.orig
192 elif diff_without_pot_creation_date_and_comments -q tails.pot.orig tails.pot; then
193 echo "Only header or comment changes in tails.pot: keeping the old one"
194 mv tails.pot.orig tails.pot
195 else
196 echo "Real changes in tails.pot: switching to the updated one"
197 rm tails.pot.orig
202 intltool_merge_desktop () {
203 extract_from_file_between_markers po/POTFILES.in \
204 '^# Files updated by intltool-update --desktop-style' '^$' \
205 | while read infile ; do
206 intltool-merge --quiet --desktop-style --utf8 \
207 po "$infile" "${infile%.in}"
208 done
211 intltool_merge_xml () {
212 extract_from_file_between_markers po/POTFILES.in \
213 '^# Files updated by intltool-update --xml-style' '^$' \
214 | while read infile ; do
215 intltool-merge --quiet --xml-style --utf8 \
216 po "$infile" "${infile%.in}"
217 done
220 ### Main
222 FORCE=no
223 KEEP_TMP_POT=no
224 while [ -n "${@:-}" ]; do
225 case "${1:-}" in
226 '--force')
227 FORCE=yes
229 '--keep-tmp-pot')
230 KEEP_TMP_POT=yes
233 echo "Unknown option: ${1}"
234 exit 1
236 esac
237 shift
238 done
240 # Schedule clean up
241 trap "rm -fr po/*.new po/*.orig ; [ "$KEEP_TMP_POT" = yes ] || rm -fr tmp/pot" EXIT
243 # Update POT files
244 mkdir -p tmp/pot
245 for prog in $PERL_PROGS ; do create_pot $prog Perl ; done
246 for prog in $PYTHON_PROGS ; do create_pot $prog Python ; done
247 for prog in $SHELL_PROGS ; do create_pot $prog Shell ; done
248 for prog in $JAVASCRIPT_PROGS ; do create_pot $prog JavaScript ; done
249 for prog in $GLADE_UI ; do create_pot $prog Glade ; done
250 intltool_update_pot
252 # If left out files are detected, intltool-update --maintain writes
253 # them to po/missing.
254 if ! no_left_out_files; then
255 echo "E: These files should be listed in POTFILES.in or POTFILES.skip:" >&2
256 cat po/missing
257 exit 3
260 # Update PO files
261 intltool_update_po $(po_languages)
263 # Update files that are actually used at runtime
264 refresh_mo $(po_languages)
265 intltool_merge_desktop
266 intltool_merge_xml
267 chmod +x config/chroot_local-includes/etc/skel/Desktop/*.desktop