refresh-translations 4.17 KB
Newer Older
1
2
#! /bin/sh

3
4
5
set -e
set -u

6
PERL_PROGS="/usr/local/bin/tails-security-check \
anonym's avatar
anonym committed
7
8
    /usr/local/lib/tails-htp-notify-user \
    /usr/local/lib/tails-virt-notify-user"
9
PYTHON_PROGS="/etc/whisperback/config.py \
anonym's avatar
anonym committed
10
    /usr/local/bin/tails-about /usr/local/sbin/tails-additional-software"
11
SHELL_PROGS="/etc/NetworkManager/dispatcher.d/60-tor-ready.sh \
anonym's avatar
anonym committed
12
13
14
15
16
17
    /usr/local/bin/electrum \
    /usr/local/bin/keepassx \
    /usr/local/bin/tails-upgrade-frontend-wrapper \
    /usr/local/lib/tails-spoof-mac \
    /usr/local/bin/tor-browser \
    /usr/local/sbin/unsafe-browser"
18
JAVASCRIPT_PROGS=" \
anonym's avatar
anonym committed
19
20
    /usr/share/gnome-shell/extensions/shutdown-helper@tails.boum.org/extension.js \
    /usr/share/gnome-shell/extensions/torstatus@tails.boum.org/extension.js \
21
"
22
23
24

LOCALE_BASEDIR=config/chroot_local-includes/usr/share/locale

25
26
27
28
### External libraries

. config/chroot_local-includes/usr/local/lib/tails-shell-library/po.sh

29
### Functions
30

31
normalize_pot () {
32
33
34
    sed --regexp-extended \
        -i 's@^"Content-Type: text/plain; charset=CHARSET\\n"@"Content-Type: text/plain; charset=UTF-8\\n"@' \
        "${@}"
35
36
}

37
prog_potfile () {
anonym's avatar
anonym committed
38
39
40
41
42
43
44
45
46
47
48
49
    prog=$1

    progpath="config/chroot_local-includes$prog"
    case $prog in
        /usr/share/gnome-shell/extensions/shutdown-helper@tails.boum.org/extension.js)
            domain=shutdown-helper-extension.js
            ;;
        *)
            domain=$(basename $prog)
            ;;
    esac
    echo "tmp/pot/${domain}.pot"
50
51
}

52
create_pot () {
anonym's avatar
anonym committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
    prog=$1
    proglang=$2
    progpath="config/chroot_local-includes${prog}"
    if [ -e "${progpath}" ]; then
        pot="$(prog_potfile "${prog}")"
        mkdir -p "$(dirname ${pot})"
        xgettext --language="${proglang}" --from-code=UTF-8 \
                 -o "${pot}" "${progpath}"
        normalize_pot "${pot}"
    else
        echo "error: We are supposed to create a POT file for '${prog}'" \
             "but '${progpath}' does not exist"
        exit 1
    fi
67
68
}

Tails developers's avatar
Tails developers committed
69
po_file () {
anonym's avatar
anonym committed
70
    locale=$1
amnesia's avatar
amnesia committed
71

anonym's avatar
anonym committed
72
    echo "po/${locale}.po"
73
74
}

75
mo_file () {
anonym's avatar
anonym committed
76
    locale=$1
77

anonym's avatar
anonym committed
78
    echo "${LOCALE_BASEDIR}/${locale}/LC_MESSAGES/tails.mo"
79
80
}

81
refresh_mo () {
anonym's avatar
anonym committed
82
83
84
85
86
87
    for locale in "$@" ; do
        po=$(po_file $locale)
        mo=$(mo_file $locale)
        mkdir -p $(dirname "$mo")
        msgfmt -o "${mo}" "${po}"
    done
88
89
}

90
no_left_out_files () {
anonym's avatar
anonym committed
91
92
93
    (cd po && intltool-update --maintain)
    [ ! -e po/missing ] || return 1
    return 0
94
95
}

96
intltool_update_pot () {
anonym's avatar
anonym committed
97
98
99
100
101
102
103
104
105
    (
        cd po
        cp -a tails.pot tails.pot.orig
        intltool-update --pot --gettext-package=tails
        normalize_pot tails.pot tails.pot.orig

        if [ "${FORCE}" = yes ]; then
            echo "Force-updating 'tails.pot'."
            rm tails.pot.orig
106
        elif diff_without_pot_creation_date_and_comments -q tails.pot.orig tails.pot; then
anonym's avatar
anonym committed
107
108
109
110
111
112
113
            echo "Only header or comment changes in tails.pot: keeping the old one"
            mv tails.pot.orig tails.pot
        else
            echo "Real changes in tails.pot: switching to the updated one"
            rm tails.pot.orig
        fi
    )
114
115
}

116
intltool_merge () {
anonym's avatar
anonym committed
117
118
119
120
121
    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
122
123
}

124
125
### Main

anonym's avatar
anonym committed
126
127
128
# Schedule clean up
trap "rm -fr tmp/pot po/*.new po/*.orig" EXIT

129
130
131
132
133
134
135
136
137
138
139
140
141
142
FORCE=no
while [ -n "${@:-}" ]; do
    case "${1:-}" in
        '--force')
            FORCE=yes
            ;;
        *)
            echo "Unknown option: ${1}"
            exit 1
            ;;
    esac
    shift
done

143
# Update POT files
144
mkdir -p tmp/pot
145
146
147
148
for prog in $PERL_PROGS   ; do create_pot $prog Perl   ; done
for prog in $PYTHON_PROGS ; do create_pot $prog Python ; done
for prog in $SHELL_PROGS  ; do create_pot $prog Shell  ; done
for prog in $JAVASCRIPT_PROGS  ; do create_pot $prog JavaScript ; done
149
intltool_update_pot
150

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

155
# Update PO files
156
intltool_update_po $(po_languages)
157

158
# Update files that are actually used at runtime
159
refresh_mo $(po_languages)
160
intltool_merge
161
chmod +x config/chroot_local-includes/etc/skel/Desktop/*.desktop