"don't create" is not a suggested-action
[tails.git] / refresh-translations
blob2aea1f3e25e3678c11f9671179fcb255f0a35cef
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="/etc/whisperback/config.py \
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/local/sbin/tails-additional-software \
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/source.py \
30 /usr/lib/python3/dist-packages/tails_installer/utils.py \
31 /usr/lib/python3/dist-packages/tailsgreeter/settings/persistence.py \
32 /usr/lib/python3/dist-packages/tailsgreeter/ui/add_settings_dialog.py \
33 /usr/lib/python3/dist-packages/tailsgreeter/ui/additional_settings.py \
34 /usr/lib/python3/dist-packages/tailsgreeter/ui/persistent_storage.py \
35 /usr/lib/python3/dist-packages/tailsgreeter/ui/region_settings.py \
36 /usr/lib/python3/dist-packages/tca/config.py \
37 /usr/lib/python3/dist-packages/tca/ui/main_window.py \
38 /usr/lib/python3/dist-packages/tps_frontend/application.py \
39 /usr/lib/python3/dist-packages/tps_frontend/change_passphrase_dialog.py \
40 /usr/lib/python3/dist-packages/tps_frontend/error_dialog.py \
41 /usr/lib/python3/dist-packages/tps_frontend/feature.py \
42 /usr/lib/python3/dist-packages/tps_frontend/passphrase_strength_hint.py \
43 /usr/lib/python3/dist-packages/tps_frontend/window.py \
44 /usr/lib/python3/dist-packages/unlock_veracrypt_volumes/volume.py \
45 /usr/lib/python3/dist-packages/unlock_veracrypt_volumes/volume_list.py \
46 /usr/lib/python3/dist-packages/unlock_veracrypt_volumes/volume_manager.py \
47 /usr/lib/python3/dist-packages/whisperBack/exceptions.py \
48 /usr/lib/python3/dist-packages/whisperBack/gui.py \
49 /usr/lib/python3/dist-packages/whisperBack/whisperback.py \
50 /usr/local/bin/tca \
51 /usr/local/lib/tails-additional-software-notify \
52 /usr/local/lib/tails-virt-notify-user \
53 /usr/local/sbin/tails-additional-software"
54 SHELL_PROGS=" \
55 /usr/local/bin/keepassxc \
56 /usr/local/lib/tails-spoof-mac \
57 /usr/local/bin/thunderbird \
58 /usr/bin/tor-browser \
59 /usr/local/sbin/unsafe-browser"
60 JAVASCRIPT_PROGS=" \
61 /usr/share/gnome-shell/extensions/status-menu-helper@tails.boum.org/extension.js \
62 /usr/share/gnome-shell/extensions/torstatus@tails.boum.org/extension.js \
64 GLADE_UI="\
65 /usr/share/tails/additional-software/configuration-window.ui \
68 LOCALE_BASEDIR=config/chroot_local-includes/usr/share/locale
70 ### External libraries
72 . config/chroot_local-includes/usr/local/lib/tails-shell-library/common.sh
73 . config/chroot_local-includes/usr/local/lib/tails-shell-library/po.sh
75 ### Functions
77 normalize_pot () {
78 sed --regexp-extended \
79 -i 's@^"Content-Type: text/plain; charset=CHARSET\\n"@"Content-Type: text/plain; charset=UTF-8\\n"@' \
80 "${@}"
83 prog_potfile () {
84 prog=$1
86 progpath="config/chroot_local-includes$prog"
87 case $prog in
88 /usr/share/gnome-shell/extensions/status-menu-helper@tails.boum.org/extension.js)
89 domain=status-menu-helper-extension.js
91 /usr/share/gnome-shell/extensions/torstatus@tails.boum.org/extension.js)
92 domain=torstatus-extension.js
94 /usr/lib/python3/dist-packages/tps/*)
95 domain="tps-$(basename "$prog")"
97 /usr/lib/python3/dist-packages/tps_frontend/*)
98 domain="tps-frontend-$(basename "$prog")"
100 /usr/lib/python3/dist-packages/unlock_veracrypt_volumes/*)
101 domain="unlock-veracrypt-volumes-$(basename "$prog")"
103 /usr/lib/python3/dist-packages/tailsgreeter/*)
104 domain="greeter-$(basename "$prog")"
106 /usr/lib/python*/dist-packages/tails_installer/*)
107 domain="installer-$(basename "$prog")"
109 /usr/lib/python*/dist-packages/tca/*)
110 domain="tca-$(basename "$prog")"
112 /usr/local/bin/tca)
113 domain="tca-bin"
115 /usr/lib/python3/dist-packages/whisperBack/*)
116 domain="whisperBack-$(basename "$prog")"
119 domain=$(basename "$prog")
121 esac
122 echo "tmp/pot/${domain}.pot"
125 create_pot () {
126 prog=$1
127 proglang=$2
128 progpath="config/chroot_local-includes${prog}"
129 if [ -e "${progpath}" ]; then
130 pot="$(prog_potfile "${prog}")"
131 mkdir -p "$(dirname "${pot}")"
132 case "$proglang" in
133 Perl)
134 # XXX: once we can assume libintl-perl 1.28+,
135 # generate this list of options with:
136 # perl -MLocale::TextDomain -E 'print Locale::TextDomain->options'
137 xgettext_args='--keyword'
138 xgettext_args="$xgettext_args --keyword=__"
139 xgettext_args="$xgettext_args --keyword='\$__'"
140 xgettext_args="$xgettext_args --keyword=__x"
141 xgettext_args="$xgettext_args --keyword=__n:1,2"
142 xgettext_args="$xgettext_args --keyword=__nx:1,2"
143 xgettext_args="$xgettext_args --keyword=__xn:1,2"
144 xgettext_args="$xgettext_args --keyword=__p:1c,2"
145 xgettext_args="$xgettext_args --keyword=__np:1c,2,3"
146 xgettext_args="$xgettext_args --keyword=__npx:1c,2,3"
147 xgettext_args="$xgettext_args --keyword=N__"
148 xgettext_args="$xgettext_args --keyword=N__n:1,2"
149 xgettext_args="$xgettext_args --keyword=N__p:1c,2"
150 xgettext_args="$xgettext_args --keyword=N__np:1c,2,3"
151 xgettext_args="$xgettext_args --keyword=%__'"
154 xgettext_args=
156 esac
157 # shellcheck disable=SC2086
158 xgettext --language="${proglang}" --from-code=UTF-8 \
159 $xgettext_args \
160 --add-comments="Translators:" -o "${pot}" "${progpath}"
161 if [ -f "${pot}" ]; then
162 normalize_pot "${pot}"
164 else
165 echo "error: We are supposed to create a POT file for '${prog}'" \
166 "but '${progpath}' does not exist"
167 exit 1
171 po_file () {
172 locale=$1
174 echo "po/${locale}.po"
177 mo_file () {
178 locale=$1
180 echo "${LOCALE_BASEDIR}/${locale}/LC_MESSAGES/tails.mo"
183 refresh_mo () {
184 for locale in "$@" ; do
185 po=$(po_file $locale)
186 mo=$(mo_file $locale)
187 mkdir -p "$(dirname "$mo")"
188 msgfmt --check -o "${mo}" "${po}"
189 done
192 no_left_out_files () {
193 (cd po && intltool-update --maintain)
194 [ ! -e po/missing ] || return 1
195 return 0
198 intltool_update_pot () {
200 cd po
201 cp -a tails.pot tails.pot.orig
202 intltool-update --pot --gettext-package=tails
203 normalize_pot tails.pot tails.pot.orig
205 if [ "${FORCE:-}" = yes ]; then
206 echo "Force-updating 'tails.pot'."
207 rm tails.pot.orig
208 elif diff_without_pot_creation_date_and_comments -q tails.pot.orig tails.pot; then
209 echo "Only header or comment changes in tails.pot: keeping the old one"
210 mv tails.pot.orig tails.pot
211 else
212 echo "Real changes in tails.pot: switching to the updated one"
213 rm tails.pot.orig
218 intltool_merge_desktop () {
219 extract_from_file_between_markers po/POTFILES.in \
220 '^# Files updated by intltool-update --desktop-style' '^$' \
221 | while read -r infile ; do
222 intltool-merge --quiet --desktop-style --utf8 \
223 po "$infile" "${infile%.in}"
224 done
227 intltool_merge_xml () {
228 extract_from_file_between_markers po/POTFILES.in \
229 '^# Files updated by intltool-update --xml-style' '^$' \
230 | while read -r infile ; do
231 intltool-merge --quiet --xml-style --utf8 \
232 po "$infile" "${infile%.in}"
233 done
236 ### Main
238 FORCE=no
239 KEEP_TMP_POT=no
240 while [ -n "${1:-}" ]; do
241 case "${1:-}" in
242 '--force')
243 FORCE=yes
245 '--keep-tmp-pot')
246 KEEP_TMP_POT=yes
249 echo "Unknown option: ${1}"
250 exit 1
252 esac
253 shift
254 done
256 # Schedule clean up
257 # shellcheck disable=SC2064
258 trap "rm -fr po/*.new po/*.orig ; [ '$KEEP_TMP_POT' = yes ] || rm -fr tmp/pot" EXIT
259 trap "echo refresh-translations: failed" ERR
261 # Update POT files
262 mkdir -p tmp/pot
263 for prog in $PERL_PROGS ; do create_pot "$prog" Perl ; done
264 for prog in $PYTHON_PROGS ; do create_pot "$prog" Python ; done
265 for prog in $SHELL_PROGS ; do create_pot "$prog" Shell ; done
266 for prog in $JAVASCRIPT_PROGS ; do create_pot "$prog" JavaScript ; done
267 for prog in $GLADE_UI ; do create_pot "$prog" Glade ; done
268 intltool_update_pot
270 # If left out files are detected, intltool-update --maintain writes
271 # them to po/missing.
272 if ! no_left_out_files; then
273 echo "E: These files should be listed in POTFILES.in or POTFILES.skip:" >&2
274 cat po/missing
275 exit 3
278 # Update PO files
279 # shellcheck disable=SC2046
280 intltool_update_po $(po_languages)
282 # Update files that are actually used at runtime
283 # shellcheck disable=SC2046
284 refresh_mo $(po_languages)
285 intltool_merge_desktop
286 intltool_merge_xml
287 chmod +x config/chroot_local-includes/etc/skel/Desktop/*.desktop