summaryrefslogtreecommitdiffstats
path: root/refresh-translations
blob: a846eb60328562e557f0564d7bbb3c71b28d0220 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#! /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"

LANGUAGES=$(for po in po/*.po ; do rel="${po%.po}" ; echo "${rel#po/}"; done)
LOCALE_BASEDIR=config/chroot_local-includes/usr/share/locale

### 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 "po/${locale}.po"
}

mo_file () {
   locale=$1

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

refresh_po () {
   pot=$1 ; shift
   for locale in "$@" ; do
      po=$(po_file $locale)
      mkdir -p $(dirname "$po")
      [ -e "${po}" ] || cp "${pot}" "${po}"
      msgmerge --update "${po}" "${pot}"
   done
}

refresh_mo () {
   for locale in "$@" ; do
      po=$(po_file $locale)
      mo=$(mo_file $locale)
      mkdir -p $(dirname "$mo")
      msgfmt -o "${mo}" "${po}"
   done
}

no_left_out_files () {
   (cd po && intltool-update --maintain)
   [ ! -e po/missing ] || return 1
   return 0
}

intltool_update_pot () {
   (
      cd po
      intltool-update --pot --gettext-package=tails
   )
}

intltool_update_po () {
   (
      cd po
      for locale in "$@" ; do
	 intltool-update --dist --gettext-package=tails $locale
      done
   )
}

intltool_merge () {
   grep -E --no-filename '[^ #]*\.(desktop|directory)\.in$' po/POTFILES.in \
      | while read infile ; do
           intltool-merge --quiet --desktop-style --utf8 \
	      po "$infile" "${infile%.in}"
        done
}

intltool_report () {
   (cd po && intltool-update --report --gettext-package=tails)
}

### Main

# If left out files are detected, intltool-update --maintain writes
# them to po/missing.
no_left_out_files || exit 3

# Update POT files
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
intltool_update_pot

# Update PO files
intltool_update_po $LANGUAGES

# Update files that are actually used at runtime
refresh_mo $LANGUAGES
intltool_merge

# Report back
intltool_report