Revert "This reverts commit c5a8fbe4027e9949c1cf17dfe72894a2e7a45efa"
[tails.git] / refresh-translations
blobb4dd7f90a78b68be0f93d1e232d33be7767879dd
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 PYTHON_PROGS="/etc/whisperback/config.py \
10 /usr/local/bin/electrum \
11 /usr/local/bin/replace-su-with-sudo \
12 /usr/local/bin/tails-about \
13 /usr/local/bin/tails-additional-software-config \
14 /usr/local/bin/tails-screen-locker \
15 /usr/local/bin/tails-upgrade-frontend-wrapper \
16 /usr/local/sbin/tails-additional-software \
17 /usr/local/lib/python3/dist-packages/unlock_veracrypt_volumes/volume.py \
18 /usr/local/lib/python3/dist-packages/unlock_veracrypt_volumes/volume_list.py \
19 /usr/local/lib/python3/dist-packages/unlock_veracrypt_volumes/volume_manager.py
20 /usr/local/lib/tails-additional-software-notify \
21 /usr/local/sbin/tails-additional-software"
22 SHELL_PROGS="/etc/NetworkManager/dispatcher.d/60-tor-ready.sh \
23 /usr/local/bin/keepassx \
24 /usr/local/lib/tails-spoof-mac \
25 /usr/local/bin/tor-browser \
26 /usr/local/sbin/unsafe-browser"
27 JAVASCRIPT_PROGS=" \
28 /usr/share/gnome-shell/extensions/status-menu-helper@tails.boum.org/extension.js \
29 /usr/share/gnome-shell/extensions/torstatus@tails.boum.org/extension.js \
31 GLADE_UI="\
32 /usr/share/tails/additional-software/configuration-window.ui \
35 LOCALE_BASEDIR=config/chroot_local-includes/usr/share/locale
37 ### External libraries
39 . config/chroot_local-includes/usr/local/lib/tails-shell-library/common.sh
40 . config/chroot_local-includes/usr/local/lib/tails-shell-library/po.sh
42 ### Functions
44 normalize_pot () {
45 sed --regexp-extended \
46 -i 's@^"Content-Type: text/plain; charset=CHARSET\\n"@"Content-Type: text/plain; charset=UTF-8\\n"@' \
47 "${@}"
50 prog_potfile () {
51 prog=$1
53 progpath="config/chroot_local-includes$prog"
54 case $prog in
55 /usr/share/gnome-shell/extensions/status-menu-helper@tails.boum.org/extension.js)
56 domain=status-menu-helper-extension.js
58 /usr/share/gnome-shell/extensions/torstatus@tails.boum.org/extension.js)
59 domain=torstatus-extension.js
61 /usr/local/lib/*/unlock_veracrypt_volumes/*)
62 domain="unlock-veracrypt-volumes-$(basename "$prog")"
65 domain=$(basename $prog)
67 esac
68 echo "tmp/pot/${domain}.pot"
71 create_pot () {
72 prog=$1
73 proglang=$2
74 progpath="config/chroot_local-includes${prog}"
75 if [ -e "${progpath}" ]; then
76 pot="$(prog_potfile "${prog}")"
77 mkdir -p "$(dirname ${pot})"
78 xgettext --language="${proglang}" --from-code=UTF-8 \
79 --add-comments="Translators:" -o "${pot}" "${progpath}"
80 normalize_pot "${pot}"
81 else
82 echo "error: We are supposed to create a POT file for '${prog}'" \
83 "but '${progpath}' does not exist"
84 exit 1
88 po_file () {
89 locale=$1
91 echo "po/${locale}.po"
94 mo_file () {
95 locale=$1
97 echo "${LOCALE_BASEDIR}/${locale}/LC_MESSAGES/tails.mo"
100 refresh_mo () {
101 for locale in "$@" ; do
102 po=$(po_file $locale)
103 mo=$(mo_file $locale)
104 mkdir -p $(dirname "$mo")
105 msgfmt -o "${mo}" "${po}"
106 done
109 no_left_out_files () {
110 (cd po && intltool-update --maintain)
111 [ ! -e po/missing ] || return 1
112 return 0
115 intltool_update_pot () {
117 cd po
118 cp -a tails.pot tails.pot.orig
119 intltool-update --pot --gettext-package=tails
120 normalize_pot tails.pot tails.pot.orig
122 if [ "${FORCE:-}" = yes ]; then
123 echo "Force-updating 'tails.pot'."
124 rm tails.pot.orig
125 elif diff_without_pot_creation_date_and_comments -q tails.pot.orig tails.pot; then
126 echo "Only header or comment changes in tails.pot: keeping the old one"
127 mv tails.pot.orig tails.pot
128 else
129 echo "Real changes in tails.pot: switching to the updated one"
130 rm tails.pot.orig
135 intltool_merge_desktop () {
136 extract_from_file_between_markers po/POTFILES.in \
137 '^# Files updated by intltool-update --desktop-style' '^$' \
138 | while read infile ; do
139 intltool-merge --quiet --desktop-style --utf8 \
140 po "$infile" "${infile%.in}"
141 done
144 intltool_merge_xml () {
145 extract_from_file_between_markers po/POTFILES.in \
146 '^# Files updated by intltool-update --xml-style' '^$' \
147 | while read infile ; do
148 intltool-merge --quiet --xml-style --utf8 \
149 po "$infile" "${infile%.in}"
150 done
153 ### Main
155 FORCE=no
156 KEEP_TMP_POT=no
157 while [ -n "${@:-}" ]; do
158 case "${1:-}" in
159 '--force')
160 FORCE=yes
162 '--keep-tmp-pot')
163 KEEP_TMP_POT=yes
166 echo "Unknown option: ${1}"
167 exit 1
169 esac
170 shift
171 done
173 # Schedule clean up
174 trap "rm -fr po/*.new po/*.orig ; [ "$KEEP_TMP_POT" = yes ] || rm -fr tmp/pot" EXIT
176 # Update POT files
177 mkdir -p tmp/pot
178 for prog in $PERL_PROGS ; do create_pot $prog Perl ; done
179 for prog in $PYTHON_PROGS ; do create_pot $prog Python ; done
180 for prog in $SHELL_PROGS ; do create_pot $prog Shell ; done
181 for prog in $JAVASCRIPT_PROGS ; do create_pot $prog JavaScript ; done
182 for prog in $GLADE_UI ; do create_pot $prog Glade ; done
183 intltool_update_pot
185 # If left out files are detected, intltool-update --maintain writes
186 # them to po/missing.
187 if ! no_left_out_files; then
188 echo "E: These files should be listed in POTFILES.in or POTFILES.skip:" >&2
189 cat po/missing
190 exit 3
193 # Update PO files
194 intltool_update_po $(po_languages)
196 # Update files that are actually used at runtime
197 refresh_mo $(po_languages)
198 intltool_merge_desktop
199 intltool_merge_xml
200 chmod +x config/chroot_local-includes/etc/skel/Desktop/*.desktop