Welcome Screen: fix usage of GLib.idle_add()
[tails.git] / refresh-translations
blobb7e4c17faa742b18ddc27cfe9808fc861e890e4a
1 #! /bin/bash
3 set -e
4 set -u
6 PERL_PROGS="/usr/local/bin/tails-security-check \
7 /usr/local/lib/tails-htp-notify-user \
8 $(find \
9 config/chroot_local-includes/usr/src/iuk/bin \
10 -type f \
11 | perl -p -E 's{^config/chroot_local-includes}{}' \
12 ) \
13 $(find \
14 config/chroot_local-includes/usr/src/iuk/lib \
15 config/chroot_local-includes/usr/src/perl5lib/lib \
16 -type f -name '*.pm' \
17 | perl -p -E 's{^config/chroot_local-includes}{}' \
19 PYTHON_PROGS="\
20 /usr/local/bin/electrum \
21 /usr/local/bin/replace-su-with-sudo \
22 /usr/local/bin/tails-about \
23 /usr/local/bin/tails-additional-software-config \
24 /usr/local/bin/tails-screen-locker \
25 /usr/local/bin/tails-upgrade-frontend-wrapper \
26 /usr/lib/python3/dist-packages/additional_software.py \
27 /usr/lib/python3/dist-packages/tails_installer/creator.py \
28 /usr/lib/python3/dist-packages/tails_installer/gui.py \
29 /usr/lib/python3/dist-packages/tails_installer/passphrase_dialog.py \
30 /usr/lib/python3/dist-packages/tails_installer/source.py \
31 /usr/lib/python3/dist-packages/tails_installer/utils.py \
32 /usr/lib/python3/dist-packages/tailsgreeter/settings/persistence.py \
33 /usr/lib/python3/dist-packages/tailsgreeter/ui/add_settings_dialog.py \
34 /usr/lib/python3/dist-packages/tailsgreeter/ui/additional_settings.py \
35 /usr/lib/python3/dist-packages/tailsgreeter/ui/main_window.py \
36 /usr/lib/python3/dist-packages/tailsgreeter/ui/region_settings.py \
37 /usr/lib/python3/dist-packages/tca/config.py \
38 /usr/lib/python3/dist-packages/tca/ui/main_window.py \
39 /usr/lib/python3/dist-packages/tps/configuration/binding.py \
40 /usr/lib/python3/dist-packages/tps/device.py \
41 /usr/lib/python3/dist-packages/tps_frontend/application.py \
42 /usr/lib/python3/dist-packages/tps_frontend/change_passphrase_dialog.py \
43 /usr/lib/python3/dist-packages/tps_frontend/error_dialog.py \
44 /usr/lib/python3/dist-packages/tps_frontend/feature.py \
45 /usr/lib/python3/dist-packages/tps_frontend/passphrase_strength_hint.py \
46 /usr/lib/python3/dist-packages/tps_frontend/views/features_view.py \
47 /usr/lib/python3/dist-packages/tps_frontend/window.py \
48 /usr/lib/python3/dist-packages/unlock_veracrypt_volumes/volume.py \
49 /usr/lib/python3/dist-packages/unlock_veracrypt_volumes/volume_list.py \
50 /usr/lib/python3/dist-packages/unlock_veracrypt_volumes/volume_manager.py \
51 /usr/lib/python3/dist-packages/whisperBack/exceptions.py \
52 /usr/lib/python3/dist-packages/whisperBack/gui.py \
53 /usr/lib/python3/dist-packages/whisperBack/whisperback.py \
54 /usr/local/lib/additional-software/asp-handle-package-changes \
55 /usr/local/lib/additional-software/asp-install \
56 /usr/local/lib/tails-additional-software-notify \
57 /usr/local/lib/tails-virt-notify-user"
58 SHELL_PROGS=" \
59 /usr/local/bin/keepassxc \
60 /usr/local/bin/tca \
61 /usr/local/lib/tails-spoof-mac \
62 /usr/local/lib/tails-report-disk-ioerrors \
63 /usr/local/lib/tails-report-disk-resize-errors \
64 /usr/local/bin/thunderbird \
65 /usr/bin/tor-browser \
66 /usr/local/sbin/unsafe-browser"
67 JAVASCRIPT_PROGS=" \
68 /usr/share/gnome-shell/extensions/status-menu-helper@tails.boum.org/extension.js \
69 /usr/share/gnome-shell/extensions/torstatus@tails.boum.org/extension.js \
71 GLADE_UI="\
72 /usr/share/tails/additional-software/configuration-window.ui \
75 LOCALE_BASEDIR=config/chroot_local-includes/usr/share/locale
77 ### External libraries
79 . config/chroot_local-includes/usr/local/lib/tails-shell-library/common.sh
80 . config/chroot_local-includes/usr/local/lib/tails-shell-library/po.sh
82 ### Functions
84 normalize_pot () {
85 sed --regexp-extended \
86 -i 's@^"Content-Type: text/plain; charset=CHARSET\\n"@"Content-Type: text/plain; charset=UTF-8\\n"@' \
87 "${@}"
90 prog_potfile () {
91 prog=$1
93 progpath="config/chroot_local-includes$prog"
94 case $prog in
95 /usr/share/gnome-shell/extensions/status-menu-helper@tails.boum.org/extension.js)
96 domain=status-menu-helper-extension.js
98 /usr/share/gnome-shell/extensions/torstatus@tails.boum.org/extension.js)
99 domain=torstatus-extension.js
101 /usr/lib/python3/dist-packages/tps/*)
102 domain="tps-$(basename "$prog")"
104 /usr/lib/python3/dist-packages/tps_frontend/*)
105 domain="tps-frontend-$(basename "$prog")"
107 /usr/lib/python3/dist-packages/unlock_veracrypt_volumes/*)
108 domain="unlock-veracrypt-volumes-$(basename "$prog")"
110 /usr/lib/python3/dist-packages/tailsgreeter/*)
111 domain="greeter-$(basename "$prog")"
113 /usr/lib/python*/dist-packages/tails_installer/*)
114 domain="installer-$(basename "$prog")"
116 /usr/lib/python*/dist-packages/tca/*)
117 domain="tca-$(basename "$prog")"
119 /usr/local/bin/tca)
120 domain="tca-bin"
122 /usr/lib/python3/dist-packages/whisperBack/*)
123 domain="whisperBack-$(basename "$prog")"
126 domain=$(basename "$prog")
128 esac
129 echo "tmp/pot/${domain}.pot"
132 create_pot () {
133 prog=$1
134 proglang=$2
135 progpath="config/chroot_local-includes${prog}"
136 if [ -e "${progpath}" ]; then
137 pot="$(prog_potfile "${prog}")"
138 mkdir -p "$(dirname "${pot}")"
139 case "$proglang" in
140 Perl)
141 # XXX: once we can assume libintl-perl 1.28+,
142 # generate this list of options with:
143 # perl -MLocale::TextDomain -E 'print Locale::TextDomain->options'
144 xgettext_args='--keyword'
145 xgettext_args="$xgettext_args --keyword=__"
146 xgettext_args="$xgettext_args --keyword='\$__'"
147 xgettext_args="$xgettext_args --keyword=__x"
148 xgettext_args="$xgettext_args --keyword=__n:1,2"
149 xgettext_args="$xgettext_args --keyword=__nx:1,2"
150 xgettext_args="$xgettext_args --keyword=__xn:1,2"
151 xgettext_args="$xgettext_args --keyword=__p:1c,2"
152 xgettext_args="$xgettext_args --keyword=__np:1c,2,3"
153 xgettext_args="$xgettext_args --keyword=__npx:1c,2,3"
154 xgettext_args="$xgettext_args --keyword=N__"
155 xgettext_args="$xgettext_args --keyword=N__n:1,2"
156 xgettext_args="$xgettext_args --keyword=N__p:1c,2"
157 xgettext_args="$xgettext_args --keyword=N__np:1c,2,3"
158 xgettext_args="$xgettext_args --keyword=%__'"
161 xgettext_args=
163 esac
164 # shellcheck disable=SC2086
165 xgettext --language="${proglang}" --from-code=UTF-8 \
166 $xgettext_args \
167 --add-comments="Translators:" -o "${pot}" "${progpath}"
168 if [ -f "${pot}" ]; then
169 normalize_pot "${pot}"
171 else
172 echo "error: We are supposed to create a POT file for '${prog}'" \
173 "but '${progpath}' does not exist"
174 exit 1
178 po_file () {
179 locale=$1
181 echo "po/${locale}.po"
184 mo_file () {
185 locale=$1
187 echo "${LOCALE_BASEDIR}/${locale}/LC_MESSAGES/tails.mo"
190 refresh_mo () {
191 for locale in "$@" ; do
192 po=$(po_file "$locale")
193 mo=$(mo_file "$locale")
194 mkdir -p "$(dirname "$mo")"
195 if ! msgfmt --check -o "${mo}" "${po}"; then
196 echo "Errors for locale '${locale}': restoring old file"
197 if [ -n "$(git ls-files "${po}")" ]; then
198 git restore "${po}"
199 msgfmt --check -o "${mo}" "${po}"
200 else
201 rm "${po}"
204 done
207 no_left_out_files () {
208 (cd po && intltool-update --maintain)
209 [ ! -e po/missing ] || return 1
210 return 0
213 intltool_update_pot () {
215 cd po
216 cp -a tails.pot tails.pot.orig
217 intltool-update --pot --gettext-package=tails
218 normalize_pot tails.pot tails.pot.orig
220 if [ "${FORCE:-}" = yes ]; then
221 echo "Force-updating 'tails.pot'."
222 rm tails.pot.orig
223 elif diff_without_pot_creation_date_and_comments -q tails.pot.orig tails.pot; then
224 echo "Only header or comment changes in tails.pot: keeping the old one"
225 mv tails.pot.orig tails.pot
226 else
227 echo "Real changes in tails.pot: switching to the updated one"
228 rm tails.pot.orig
233 intltool_merge_desktop () {
234 extract_from_file_between_markers po/POTFILES.in \
235 '^# Files updated by intltool-merge --desktop-style' '^$' \
236 | while read -r infile ; do
237 intltool-merge --quiet --desktop-style --utf8 \
238 po "$infile" "${infile%.in}"
239 done
242 intltool_merge_xml () {
243 extract_from_file_between_markers po/POTFILES.in \
244 '^# Files updated by intltool-merge --xml-style' '^$' \
245 | while read -r infile ; do
246 intltool-merge --quiet --xml-style --utf8 \
247 po "$infile" "${infile%.in}"
248 done
251 ### Main
253 FORCE=no
254 KEEP_TMP_POT=no
255 while [ -n "${1:-}" ]; do
256 case "${1:-}" in
257 '--force')
258 FORCE=yes
260 '--keep-tmp-pot')
261 KEEP_TMP_POT=yes
264 echo "Unknown option: ${1}"
265 exit 1
267 esac
268 shift
269 done
271 # Schedule clean up
272 # shellcheck disable=SC2064
273 trap "rm -fr po/*.new po/*.orig ; [ '$KEEP_TMP_POT' = yes ] || rm -fr tmp/pot" EXIT
274 trap "echo refresh-translations: failed" ERR
276 # Update POT files
277 mkdir -p tmp/pot
278 for prog in $PERL_PROGS ; do create_pot "$prog" Perl ; done
279 for prog in $PYTHON_PROGS ; do create_pot "$prog" Python ; done
280 for prog in $SHELL_PROGS ; do create_pot "$prog" Shell ; done
281 for prog in $JAVASCRIPT_PROGS ; do create_pot "$prog" JavaScript ; done
282 for prog in $GLADE_UI ; do create_pot "$prog" Glade ; done
283 intltool_update_pot
285 # If left out files are detected, intltool-update --maintain writes
286 # them to po/missing.
287 if ! no_left_out_files; then
288 echo "E: These files should be listed in POTFILES.in or POTFILES.skip:" >&2
289 cat po/missing
290 exit 3
293 # Update PO files
294 # shellcheck disable=SC2046
295 intltool_update_po $(po_languages)
297 # Update files that are actually used at runtime
298 # shellcheck disable=SC2046
299 refresh_mo $(po_languages)
300 intltool_merge_desktop
301 intltool_merge_xml