Merge branch 'master' of git://git.tails.boum.org/tails
[besstails.git] / refresh-translations
blobbecca814cccc4351c8db9e9200b6928c146bf82a
1 #! /bin/sh
3 set -e
4 set -u
6 PERL_PROGS="/usr/local/bin/gpgApplet /usr/local/bin/tails-security-check \
7 /usr/local/bin/tails-htp-notify-user /usr/local/bin/tails-start-i2p \
8 /usr/local/bin/tails-virt-notify-user"
9 PYTHON_PROGS="/etc/whisperback/config.py /usr/local/bin/shutdown_helper_applet \
10 /usr/local/bin/tails-about /usr/local/sbin/tails-additional-software"
11 SHELL_PROGS="/usr/local/sbin/unsafe-browser"
13 LANGUAGES=$(for po in po/*.po ; do rel="${po%.po}" ; echo "${rel#po/}"; done)
14 LOCALE_BASEDIR=config/chroot_local-includes/usr/share/locale
16 ### Functions
18 prog_potfile () {
19 prog=$1
21 progpath="config/chroot_local-includes$prog"
22 domain=$(basename $prog)
23 echo "tmp/pot/${domain}.pot"
26 refresh_pot () {
27 prog=$1
28 proglang=$2
30 progpath="config/chroot_local-includes$prog"
31 pot=$(prog_potfile $prog)
33 mkdir -p "$(dirname $pot)"
35 if [ -e "${progpath}" ]; then
36 xgettext --language="${proglang}" --from-code=UTF-8 \
37 -o "${pot}" "${progpath}"
38 sed -i "s@^\"Content-Type: text/plain\; charset=CHARSET\\\n\"@\"Content-Type: text/plain\; charset=UTF-8\\\n\"@" "${pot}"
42 po_file () {
43 locale=$1
45 echo "po/${locale}.po"
48 mo_file () {
49 locale=$1
51 echo "${LOCALE_BASEDIR}/${locale}/LC_MESSAGES/tails.mo"
54 refresh_mo () {
55 for locale in "$@" ; do
56 po=$(po_file $locale)
57 mo=$(mo_file $locale)
58 mkdir -p $(dirname "$mo")
59 msgfmt -o "${mo}" "${po}"
60 done
63 no_left_out_files () {
64 (cd po && intltool-update --maintain)
65 [ ! -e po/missing ] || return 1
66 return 0
69 intltool_update_pot () {
71 cd po
72 intltool-update --pot --gettext-package=tails
76 intltool_update_po () {
78 cd po
79 for locale in "$@" ; do
80 intltool-update --dist --gettext-package=tails $locale
81 done
85 intltool_merge () {
86 grep -E --no-filename '[^ #]*\.(desktop|directory)\.in$' po/POTFILES.in \
87 | while read infile ; do
88 intltool-merge --quiet --desktop-style --utf8 \
89 po "$infile" "${infile%.in}"
90 done
93 intltool_report () {
94 (cd po && intltool-update --report --gettext-package=tails)
97 ### Main
99 # Update POT files
100 mkdir -p tmp/pot
101 for prog in $PERL_PROGS ; do refresh_pot $prog Perl ; done
102 for prog in $PYTHON_PROGS ; do refresh_pot $prog Python ; done
103 for prog in $SHELL_PROGS ; do refresh_pot $prog Shell ; done
104 intltool_update_pot
106 # If left out files are detected, intltool-update --maintain writes
107 # them to po/missing.
108 no_left_out_files || exit 3
110 # Update PO files
111 intltool_update_po $LANGUAGES
113 # Update files that are actually used at runtime
114 refresh_mo $LANGUAGES
115 intltool_merge
117 # Report back
118 intltool_report