summaryrefslogtreecommitdiffstats
path: root/refresh-translations
blob: b33d26bf29c975c23f99dde3281beb5745c76eaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#! /bin/sh

set -e
set -u

PERL_PROGS="/usr/local/bin/gpgApplet /usr/local/bin/tails-security-check \
   /usr/local/bin/tails-htp-notify-user /usr/local/bin/tails-start-i2p \
   /usr/local/bin/tails-virt-notify-user"
PYTHON_PROGS="/etc/whisperback/config.py /usr/local/bin/shutdown_helper_applet \
   /usr/local/bin/tails-about /usr/local/sbin/tails-additional-software"
SHELL_PROGS="/usr/local/sbin/unsafe-browser"

LOCALE_BASEDIR=config/chroot_local-includes/usr/share/locale
POTFILE=config/chroot_local-includes/usr/share/tails/messages.pot

# get AMNESIA_SUPPORTED_LANGUAGES
. config/amnesia
if [ -e config/amnesia.local ] ; then
   . config/amnesia.local
fi

### Functions

prog_potfile () {
   prog=$1

   progpath="config/chroot_local-includes$prog"
   domain=$(basename $prog)
   sharedir="config/chroot_local-includes/usr/share/${domain}"
   pot="${sharedir}/messages.pot"

   echo $pot
}

refresh_pot () {
   prog=$1
   proglang=$2

   progpath="config/chroot_local-includes$prog"
   pot=$(prog_potfile $prog)

   mkdir -p "$(dirname $pot)"

   if [ -e "${progpath}" ]; then
      xgettext --language="${proglang}" --from-code=UTF-8 \
        -o "${pot}" "${progpath}"
      sed -i "s@^\"Content-Type: text/plain\; charset=CHARSET\\\n\"@\"Content-Type: text/plain\; charset=UTF-8\\\n\"@" "${pot}"
   fi
}

po_file () {
   locale=$1

   echo "${LOCALE_BASEDIR}/${locale}/LC_MESSAGES/tails.po"
}

concat_pot_files () {
   msgcat --to-code=UTF-8 \
      $(for prog in $@ ; do echo -n "$(prog_potfile $prog) " ; done)
}

refresh_po_and_mo () {
   pot=$1 ; shift
   for locale in "$@" ; do
      po=$(po_file $locale)
      mo=$(echo "$po" | sed -e s,\.po$,.mo,)
      mkdir -p $(dirname "$po")
      [ -e "${po}" ] || cp "${pot}" "${po}"
      msgmerge --update "${po}" "${pot}"
      msgfmt -o "${mo}" "${po}"
   done
}

### Main

mkdir -p $(dirname $POTFILE)

for prog in $PERL_PROGS   ; do refresh_pot $prog Perl   ; done
for prog in $PYTHON_PROGS ; do refresh_pot $prog Python ; done
for prog in $SHELL_PROGS  ; do refresh_pot $prog Shell  ; done

concat_pot_files $PERL_PROGS $PYTHON_PROGS $SHELL_PROGS > $POTFILE

refresh_po_and_mo $POTFILE $AMNESIA_SUPPORTED_LANGUAGES