Update changelog for 5.14.
[tails.git] / refresh-translations
blobcd93dffdbe8ef5f178c2002e0ef286e8665bccaa
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/mount.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/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/bin/tca \
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/lib/tails-spoof-mac \
62 /usr/local/bin/thunderbird \
63 /usr/bin/tor-browser \
64 /usr/local/sbin/unsafe-browser"
65 JAVASCRIPT_PROGS=" \
66 /usr/share/gnome-shell/extensions/status-menu-helper@tails.boum.org/extension.js \
67 /usr/share/gnome-shell/extensions/torstatus@tails.boum.org/extension.js \
69 GLADE_UI="\
70 /usr/share/tails/additional-software/configuration-window.ui \
73 LOCALE_BASEDIR=config/chroot_local-includes/usr/share/locale
75 ### External libraries
77 . config/chroot_local-includes/usr/local/lib/tails-shell-library/common.sh
78 . config/chroot_local-includes/usr/local/lib/tails-shell-library/po.sh
80 ### Functions
82 normalize_pot () {
83 sed --regexp-extended \
84 -i 's@^"Content-Type: text/plain; charset=CHARSET\\n"@"Content-Type: text/plain; charset=UTF-8\\n"@' \
85 "${@}"
88 prog_potfile () {
89 prog=$1
91 progpath="config/chroot_local-includes$prog"
92 case $prog in
93 /usr/share/gnome-shell/extensions/status-menu-helper@tails.boum.org/extension.js)
94 domain=status-menu-helper-extension.js
96 /usr/share/gnome-shell/extensions/torstatus@tails.boum.org/extension.js)
97 domain=torstatus-extension.js
99 /usr/lib/python3/dist-packages/tps/*)
100 domain="tps-$(basename "$prog")"
102 /usr/lib/python3/dist-packages/tps_frontend/*)
103 domain="tps-frontend-$(basename "$prog")"
105 /usr/lib/python3/dist-packages/unlock_veracrypt_volumes/*)
106 domain="unlock-veracrypt-volumes-$(basename "$prog")"
108 /usr/lib/python3/dist-packages/tailsgreeter/*)
109 domain="greeter-$(basename "$prog")"
111 /usr/lib/python*/dist-packages/tails_installer/*)
112 domain="installer-$(basename "$prog")"
114 /usr/lib/python*/dist-packages/tca/*)
115 domain="tca-$(basename "$prog")"
117 /usr/local/bin/tca)
118 domain="tca-bin"
120 /usr/lib/python3/dist-packages/whisperBack/*)
121 domain="whisperBack-$(basename "$prog")"
124 domain=$(basename "$prog")
126 esac
127 echo "tmp/pot/${domain}.pot"
130 create_pot () {
131 prog=$1
132 proglang=$2
133 progpath="config/chroot_local-includes${prog}"
134 if [ -e "${progpath}" ]; then
135 pot="$(prog_potfile "${prog}")"
136 mkdir -p "$(dirname "${pot}")"
137 case "$proglang" in
138 Perl)
139 # XXX: once we can assume libintl-perl 1.28+,
140 # generate this list of options with:
141 # perl -MLocale::TextDomain -E 'print Locale::TextDomain->options'
142 xgettext_args='--keyword'
143 xgettext_args="$xgettext_args --keyword=__"
144 xgettext_args="$xgettext_args --keyword='\$__'"
145 xgettext_args="$xgettext_args --keyword=__x"
146 xgettext_args="$xgettext_args --keyword=__n:1,2"
147 xgettext_args="$xgettext_args --keyword=__nx:1,2"
148 xgettext_args="$xgettext_args --keyword=__xn:1,2"
149 xgettext_args="$xgettext_args --keyword=__p:1c,2"
150 xgettext_args="$xgettext_args --keyword=__np:1c,2,3"
151 xgettext_args="$xgettext_args --keyword=__npx:1c,2,3"
152 xgettext_args="$xgettext_args --keyword=N__"
153 xgettext_args="$xgettext_args --keyword=N__n:1,2"
154 xgettext_args="$xgettext_args --keyword=N__p:1c,2"
155 xgettext_args="$xgettext_args --keyword=N__np:1c,2,3"
156 xgettext_args="$xgettext_args --keyword=%__'"
159 xgettext_args=
161 esac
162 # shellcheck disable=SC2086
163 xgettext --language="${proglang}" --from-code=UTF-8 \
164 $xgettext_args \
165 --add-comments="Translators:" -o "${pot}" "${progpath}"
166 if [ -f "${pot}" ]; then
167 normalize_pot "${pot}"
169 else
170 echo "error: We are supposed to create a POT file for '${prog}'" \
171 "but '${progpath}' does not exist"
172 exit 1
176 po_file () {
177 locale=$1
179 echo "po/${locale}.po"
182 mo_file () {
183 locale=$1
185 echo "${LOCALE_BASEDIR}/${locale}/LC_MESSAGES/tails.mo"
188 refresh_mo () {
189 for locale in "$@" ; do
190 po=$(po_file "$locale")
191 mo=$(mo_file "$locale")
192 mkdir -p "$(dirname "$mo")"
193 if ! msgfmt --check -o "${mo}" "${po}"; then
194 echo "Errors for locale '${locale}': restoring old file"
195 if [ -n "$(git ls-files "${po}")" ]; then
196 git restore "${po}"
197 msgfmt --check -o "${mo}" "${po}"
198 else
199 rm "${po}"
202 done
205 no_left_out_files () {
206 (cd po && intltool-update --maintain)
207 [ ! -e po/missing ] || return 1
208 return 0
211 intltool_update_pot () {
213 cd po
214 cp -a tails.pot tails.pot.orig
215 intltool-update --pot --gettext-package=tails
216 normalize_pot tails.pot tails.pot.orig
218 if [ "${FORCE:-}" = yes ]; then
219 echo "Force-updating 'tails.pot'."
220 rm tails.pot.orig
221 elif diff_without_pot_creation_date_and_comments -q tails.pot.orig tails.pot; then
222 echo "Only header or comment changes in tails.pot: keeping the old one"
223 mv tails.pot.orig tails.pot
224 else
225 echo "Real changes in tails.pot: switching to the updated one"
226 rm tails.pot.orig
231 intltool_merge_desktop () {
232 extract_from_file_between_markers po/POTFILES.in \
233 '^# Files updated by intltool-update --desktop-style' '^$' \
234 | while read -r infile ; do
235 intltool-merge --quiet --desktop-style --utf8 \
236 po "$infile" "${infile%.in}"
237 done
240 intltool_merge_xml () {
241 extract_from_file_between_markers po/POTFILES.in \
242 '^# Files updated by intltool-update --xml-style' '^$' \
243 | while read -r infile ; do
244 intltool-merge --quiet --xml-style --utf8 \
245 po "$infile" "${infile%.in}"
246 done
249 ### Main
251 FORCE=no
252 KEEP_TMP_POT=no
253 while [ -n "${1:-}" ]; do
254 case "${1:-}" in
255 '--force')
256 FORCE=yes
258 '--keep-tmp-pot')
259 KEEP_TMP_POT=yes
262 echo "Unknown option: ${1}"
263 exit 1
265 esac
266 shift
267 done
269 # Schedule clean up
270 # shellcheck disable=SC2064
271 trap "rm -fr po/*.new po/*.orig ; [ '$KEEP_TMP_POT' = yes ] || rm -fr tmp/pot" EXIT
272 trap "echo refresh-translations: failed" ERR
274 # Update POT files
275 mkdir -p tmp/pot
276 for prog in $PERL_PROGS ; do create_pot "$prog" Perl ; done
277 for prog in $PYTHON_PROGS ; do create_pot "$prog" Python ; done
278 for prog in $SHELL_PROGS ; do create_pot "$prog" Shell ; done
279 for prog in $JAVASCRIPT_PROGS ; do create_pot "$prog" JavaScript ; done
280 for prog in $GLADE_UI ; do create_pot "$prog" Glade ; done
281 intltool_update_pot
283 # If left out files are detected, intltool-update --maintain writes
284 # them to po/missing.
285 if ! no_left_out_files; then
286 echo "E: These files should be listed in POTFILES.in or POTFILES.skip:" >&2
287 cat po/missing
288 exit 3
291 # Update PO files
292 # shellcheck disable=SC2046
293 intltool_update_po $(po_languages)
295 # Update files that are actually used at runtime
296 # shellcheck disable=SC2046
297 refresh_mo $(po_languages)
298 intltool_merge_desktop
299 intltool_merge_xml
300 chmod +x config/chroot_local-includes/etc/skel/Desktop/*.desktop