Remove unnecessary reason to use nested VMs to build Tails in Jenkins.
[tails.git] / refresh-translations
blob740e9fe671021bb044f5a3976e1d7ba81b552197
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/tails-about /usr/local/sbin/tails-additional-software"
11 SHELL_PROGS="/etc/NetworkManager/dispatcher.d/60-tor-ready.sh \
12 /usr/local/bin/electrum \
13 /usr/local/bin/keepassx \
14 /usr/local/bin/tails-upgrade-frontend-wrapper \
15 /usr/local/lib/tails-spoof-mac \
16 /usr/local/bin/tor-browser \
17 /usr/local/sbin/unsafe-browser"
18 JAVASCRIPT_PROGS=" \
19 /usr/share/gnome-shell/extensions/shutdown-helper@tails.boum.org/extension.js \
20 /usr/share/gnome-shell/extensions/torstatus@tails.boum.org/extension.js \
23 LOCALE_BASEDIR=config/chroot_local-includes/usr/share/locale
25 ### External libraries
27 . config/chroot_local-includes/usr/local/lib/tails-shell-library/common.sh
28 . config/chroot_local-includes/usr/local/lib/tails-shell-library/po.sh
30 ### Functions
32 normalize_pot () {
33 sed --regexp-extended \
34 -i 's@^"Content-Type: text/plain; charset=CHARSET\\n"@"Content-Type: text/plain; charset=UTF-8\\n"@' \
35 "${@}"
38 prog_potfile () {
39 prog=$1
41 progpath="config/chroot_local-includes$prog"
42 case $prog in
43 /usr/share/gnome-shell/extensions/shutdown-helper@tails.boum.org/extension.js)
44 domain=shutdown-helper-extension.js
47 domain=$(basename $prog)
49 esac
50 echo "tmp/pot/${domain}.pot"
53 create_pot () {
54 prog=$1
55 proglang=$2
56 progpath="config/chroot_local-includes${prog}"
57 if [ -e "${progpath}" ]; then
58 pot="$(prog_potfile "${prog}")"
59 mkdir -p "$(dirname ${pot})"
60 xgettext --language="${proglang}" --from-code=UTF-8 \
61 -o "${pot}" "${progpath}"
62 normalize_pot "${pot}"
63 else
64 echo "error: We are supposed to create a POT file for '${prog}'" \
65 "but '${progpath}' does not exist"
66 exit 1
70 po_file () {
71 locale=$1
73 echo "po/${locale}.po"
76 mo_file () {
77 locale=$1
79 echo "${LOCALE_BASEDIR}/${locale}/LC_MESSAGES/tails.mo"
82 refresh_mo () {
83 for locale in "$@" ; do
84 po=$(po_file $locale)
85 mo=$(mo_file $locale)
86 mkdir -p $(dirname "$mo")
87 msgfmt -o "${mo}" "${po}"
88 done
91 no_left_out_files () {
92 (cd po && intltool-update --maintain)
93 [ ! -e po/missing ] || return 1
94 return 0
97 intltool_update_pot () {
99 cd po
100 cp -a tails.pot tails.pot.orig
101 intltool-update --pot --gettext-package=tails
102 normalize_pot tails.pot tails.pot.orig
104 if [ "${FORCE:-}" = yes ]; then
105 echo "Force-updating 'tails.pot'."
106 rm tails.pot.orig
107 elif diff_without_pot_creation_date_and_comments -q tails.pot.orig tails.pot; then
108 echo "Only header or comment changes in tails.pot: keeping the old one"
109 mv tails.pot.orig tails.pot
110 else
111 echo "Real changes in tails.pot: switching to the updated one"
112 rm tails.pot.orig
117 intltool_merge_desktop () {
118 extract_from_file_between_markers po/POTFILES.in \
119 '^# Files updated by intltool-update --desktop-style' '^$' \
120 | while read infile ; do
121 intltool-merge --quiet --desktop-style --utf8 \
122 po "$infile" "${infile%.in}"
123 done
126 intltool_merge_xml () {
127 extract_from_file_between_markers po/POTFILES.in \
128 '^# Files updated by intltool-update --xml-style' '^$' \
129 | while read infile ; do
130 intltool-merge --quiet --xml-style --utf8 \
131 po "$infile" "${infile%.in}"
132 done
135 ### Main
137 # Schedule clean up
138 trap "rm -fr tmp/pot po/*.new po/*.orig" EXIT
140 FORCE=no
141 while [ -n "${@:-}" ]; do
142 case "${1:-}" in
143 '--force')
144 FORCE=yes
147 echo "Unknown option: ${1}"
148 exit 1
150 esac
151 shift
152 done
154 # Update POT files
155 mkdir -p tmp/pot
156 for prog in $PERL_PROGS ; do create_pot $prog Perl ; done
157 for prog in $PYTHON_PROGS ; do create_pot $prog Python ; done
158 for prog in $SHELL_PROGS ; do create_pot $prog Shell ; done
159 for prog in $JAVASCRIPT_PROGS ; do create_pot $prog JavaScript ; done
160 intltool_update_pot
162 # If left out files are detected, intltool-update --maintain writes
163 # them to po/missing.
164 no_left_out_files || exit 3
166 # Update PO files
167 intltool_update_po $(po_languages)
169 # Update files that are actually used at runtime
170 refresh_mo $(po_languages)
171 intltool_merge_desktop
172 intltool_merge_xml
173 chmod +x config/chroot_local-includes/etc/skel/Desktop/*.desktop