Merge remote-tracking branch 'origin/stable' into devel
[tails.git] / refresh-translations
blob33da0c8bb87d401bc7105429bbea2535855ae54a
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/persistent_storage.py \
37 /usr/lib/python3/dist-packages/tailsgreeter/ui/region_settings.py \
38 /usr/lib/python3/dist-packages/tca/config.py \
39 /usr/lib/python3/dist-packages/tca/ui/main_window.py \
40 /usr/lib/python3/dist-packages/tps/configuration/binding.py \
41 /usr/lib/python3/dist-packages/tps/device.py \
42 /usr/lib/python3/dist-packages/tps_frontend/application.py \
43 /usr/lib/python3/dist-packages/tps_frontend/change_passphrase_dialog.py \
44 /usr/lib/python3/dist-packages/tps_frontend/error_dialog.py \
45 /usr/lib/python3/dist-packages/tps_frontend/feature.py \
46 /usr/lib/python3/dist-packages/tps_frontend/passphrase_strength_hint.py \
47 /usr/lib/python3/dist-packages/tps_frontend/views/features_view.py \
48 /usr/lib/python3/dist-packages/tps_frontend/window.py \
49 /usr/lib/python3/dist-packages/unlock_veracrypt_volumes/volume.py \
50 /usr/lib/python3/dist-packages/unlock_veracrypt_volumes/volume_list.py \
51 /usr/lib/python3/dist-packages/unlock_veracrypt_volumes/volume_manager.py \
52 /usr/lib/python3/dist-packages/whisperBack/exceptions.py \
53 /usr/lib/python3/dist-packages/whisperBack/gui.py \
54 /usr/lib/python3/dist-packages/whisperBack/whisperback.py \
55 /usr/local/lib/additional-software/asp-handle-package-changes \
56 /usr/local/lib/additional-software/asp-install \
57 /usr/local/lib/tails-additional-software-notify \
58 /usr/local/lib/tails-virt-notify-user"
59 SHELL_PROGS=" \
60 /usr/local/bin/keepassxc \
61 /usr/local/bin/tca \
62 /usr/local/lib/tails-spoof-mac \
63 /usr/local/lib/tails-report-disk-ioerrors \
64 /usr/local/lib/tails-report-disk-resize-errors \
65 /usr/local/bin/thunderbird \
66 /usr/bin/tor-browser \
67 /usr/local/sbin/unsafe-browser"
68 JAVASCRIPT_PROGS=" \
69 /usr/share/gnome-shell/extensions/status-menu-helper@tails.boum.org/extension.js \
70 /usr/share/gnome-shell/extensions/torstatus@tails.boum.org/extension.js \
72 GLADE_UI="\
73 /usr/share/tails/additional-software/configuration-window.ui \
76 LOCALE_BASEDIR=config/chroot_local-includes/usr/share/locale
78 ### External libraries
80 . config/chroot_local-includes/usr/local/lib/tails-shell-library/common.sh
81 . config/chroot_local-includes/usr/local/lib/tails-shell-library/po.sh
83 ### Functions
85 normalize_pot () {
86 sed --regexp-extended \
87 -i 's@^"Content-Type: text/plain; charset=CHARSET\\n"@"Content-Type: text/plain; charset=UTF-8\\n"@' \
88 "${@}"
91 prog_potfile () {
92 prog=$1
94 progpath="config/chroot_local-includes$prog"
95 case $prog in
96 /usr/share/gnome-shell/extensions/status-menu-helper@tails.boum.org/extension.js)
97 domain=status-menu-helper-extension.js
99 /usr/share/gnome-shell/extensions/torstatus@tails.boum.org/extension.js)
100 domain=torstatus-extension.js
102 /usr/lib/python3/dist-packages/tps/*)
103 domain="tps-$(basename "$prog")"
105 /usr/lib/python3/dist-packages/tps_frontend/*)
106 domain="tps-frontend-$(basename "$prog")"
108 /usr/lib/python3/dist-packages/unlock_veracrypt_volumes/*)
109 domain="unlock-veracrypt-volumes-$(basename "$prog")"
111 /usr/lib/python3/dist-packages/tailsgreeter/*)
112 domain="greeter-$(basename "$prog")"
114 /usr/lib/python*/dist-packages/tails_installer/*)
115 domain="installer-$(basename "$prog")"
117 /usr/lib/python*/dist-packages/tca/*)
118 domain="tca-$(basename "$prog")"
120 /usr/local/bin/tca)
121 domain="tca-bin"
123 /usr/lib/python3/dist-packages/whisperBack/*)
124 domain="whisperBack-$(basename "$prog")"
127 domain=$(basename "$prog")
129 esac
130 echo "tmp/pot/${domain}.pot"
133 create_pot () {
134 prog=$1
135 proglang=$2
136 progpath="config/chroot_local-includes${prog}"
137 if [ -e "${progpath}" ]; then
138 pot="$(prog_potfile "${prog}")"
139 mkdir -p "$(dirname "${pot}")"
140 case "$proglang" in
141 Perl)
142 # XXX: once we can assume libintl-perl 1.28+,
143 # generate this list of options with:
144 # perl -MLocale::TextDomain -E 'print Locale::TextDomain->options'
145 xgettext_args='--keyword'
146 xgettext_args="$xgettext_args --keyword=__"
147 xgettext_args="$xgettext_args --keyword='\$__'"
148 xgettext_args="$xgettext_args --keyword=__x"
149 xgettext_args="$xgettext_args --keyword=__n:1,2"
150 xgettext_args="$xgettext_args --keyword=__nx:1,2"
151 xgettext_args="$xgettext_args --keyword=__xn:1,2"
152 xgettext_args="$xgettext_args --keyword=__p:1c,2"
153 xgettext_args="$xgettext_args --keyword=__np:1c,2,3"
154 xgettext_args="$xgettext_args --keyword=__npx:1c,2,3"
155 xgettext_args="$xgettext_args --keyword=N__"
156 xgettext_args="$xgettext_args --keyword=N__n:1,2"
157 xgettext_args="$xgettext_args --keyword=N__p:1c,2"
158 xgettext_args="$xgettext_args --keyword=N__np:1c,2,3"
159 xgettext_args="$xgettext_args --keyword=%__'"
162 xgettext_args=
164 esac
165 # shellcheck disable=SC2086
166 xgettext --language="${proglang}" --from-code=UTF-8 \
167 $xgettext_args \
168 --add-comments="Translators:" -o "${pot}" "${progpath}"
169 if [ -f "${pot}" ]; then
170 normalize_pot "${pot}"
172 else
173 echo "error: We are supposed to create a POT file for '${prog}'" \
174 "but '${progpath}' does not exist"
175 exit 1
179 po_file () {
180 locale=$1
182 echo "po/${locale}.po"
185 mo_file () {
186 locale=$1
188 echo "${LOCALE_BASEDIR}/${locale}/LC_MESSAGES/tails.mo"
191 refresh_mo () {
192 for locale in "$@" ; do
193 po=$(po_file "$locale")
194 mo=$(mo_file "$locale")
195 mkdir -p "$(dirname "$mo")"
196 if ! msgfmt --check -o "${mo}" "${po}"; then
197 echo "Errors for locale '${locale}': restoring old file"
198 if [ -n "$(git ls-files "${po}")" ]; then
199 git restore "${po}"
200 msgfmt --check -o "${mo}" "${po}"
201 else
202 rm "${po}"
205 done
208 no_left_out_files () {
209 (cd po && intltool-update --maintain)
210 [ ! -e po/missing ] || return 1
211 return 0
214 intltool_update_pot () {
216 cd po
217 cp -a tails.pot tails.pot.orig
218 intltool-update --pot --gettext-package=tails
219 normalize_pot tails.pot tails.pot.orig
221 if [ "${FORCE:-}" = yes ]; then
222 echo "Force-updating 'tails.pot'."
223 rm tails.pot.orig
224 elif diff_without_pot_creation_date_and_comments -q tails.pot.orig tails.pot; then
225 echo "Only header or comment changes in tails.pot: keeping the old one"
226 mv tails.pot.orig tails.pot
227 else
228 echo "Real changes in tails.pot: switching to the updated one"
229 rm tails.pot.orig
234 intltool_merge_desktop () {
235 extract_from_file_between_markers po/POTFILES.in \
236 '^# Files updated by intltool-update --desktop-style' '^$' \
237 | while read -r infile ; do
238 intltool-merge --quiet --desktop-style --utf8 \
239 po "$infile" "${infile%.in}"
240 done
243 intltool_merge_xml () {
244 extract_from_file_between_markers po/POTFILES.in \
245 '^# Files updated by intltool-update --xml-style' '^$' \
246 | while read -r infile ; do
247 intltool-merge --quiet --xml-style --utf8 \
248 po "$infile" "${infile%.in}"
249 done
252 ### Main
254 FORCE=no
255 KEEP_TMP_POT=no
256 while [ -n "${1:-}" ]; do
257 case "${1:-}" in
258 '--force')
259 FORCE=yes
261 '--keep-tmp-pot')
262 KEEP_TMP_POT=yes
265 echo "Unknown option: ${1}"
266 exit 1
268 esac
269 shift
270 done
272 # Schedule clean up
273 # shellcheck disable=SC2064
274 trap "rm -fr po/*.new po/*.orig ; [ '$KEEP_TMP_POT' = yes ] || rm -fr tmp/pot" EXIT
275 trap "echo refresh-translations: failed" ERR
277 # Update POT files
278 mkdir -p tmp/pot
279 for prog in $PERL_PROGS ; do create_pot "$prog" Perl ; done
280 for prog in $PYTHON_PROGS ; do create_pot "$prog" Python ; done
281 for prog in $SHELL_PROGS ; do create_pot "$prog" Shell ; done
282 for prog in $JAVASCRIPT_PROGS ; do create_pot "$prog" JavaScript ; done
283 for prog in $GLADE_UI ; do create_pot "$prog" Glade ; done
284 intltool_update_pot
286 # If left out files are detected, intltool-update --maintain writes
287 # them to po/missing.
288 if ! no_left_out_files; then
289 echo "E: These files should be listed in POTFILES.in or POTFILES.skip:" >&2
290 cat po/missing
291 exit 3
294 # Update PO files
295 # shellcheck disable=SC2046
296 intltool_update_po $(po_languages)
298 # Update files that are actually used at runtime
299 # shellcheck disable=SC2046
300 refresh_mo $(po_languages)
301 intltool_merge_desktop
302 intltool_merge_xml