summaryrefslogtreecommitdiff
path: root/debian/scripts/debconf-updatepo
blob: ad7fffcf9d7b73f89d85f67b067c44a3fb8ba8c0 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/sh

# This is a replacement for the real debconf-updatepo, which unfortunately
# mangles our debian/po/templates.pot file beyond recognition.

#  Copyright (C) 2002-2004  Denis Barbier <barbier@debian.org>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or (at
#  your option) any later version.
#
#  This program is distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the
#  Free Software Foundation, Inc.,
#  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

# Branden Robinson, 2004-11-11

PROGNAME=${0##*/}

usage() {
        cat <<EOF
Usage: $PROGNAME [OPTIONS]
Options:
  -h,  --help          display this help message
  -v,  --verbose       enable verbose mode
  --podir=DIR          specify PO directory (searched by default in
                       debian/po, ./po and ../po)
  --pot-header=FILE    replace beginning of generated POT file with FILE
                       (relative to PO directory)
  --skip-pot           skip POT file; update only PO files
EOF
}

trace () {
        if [ -n "$verbose" ]
        then
                echo "$PROGNAME: $*" >&2
        fi
}

error () {
        echo "$PROGNAME: error: $*" >&2
        exit 1
}

die () {
        error "$*"
        exit 1
}

repair_header () {
        if [ $# -ne 2 ]
        then
                die "repair_header() needs 2 arguments; got $#"
        fi

        trace "repairing header of $2"
        ( cat "$1"; sed -n '/^$/,$p' "$2" ) >"$2.new" && mv "$2.new" "$2"
}

: ${PODEBCONF_LIB=/usr/share/intltool-debian}
INTLTOOL_EXTRACT=${PODEBCONF_LIB}/intltool-extract
export INTLTOOL_EXTRACT

#  See intltool-extract
INTLTOOL_DEBIAN_TYPE=po-debconf
export INTLTOOL_DEBIAN_TYPE

# Prevent automatic conversion to UTF-8 by Perl.
unset LANGUAGE LANG LC_ALL LC_CTYPE

help=
verbose=
podir=
pot_header=
skip_pot=

for option
do
        if [ -n "$prev" ]; then
                eval "$prev=\$option"
                prev=
                shift
                continue
        fi
        optarg=$(expr "$option" : '[^=]*=\(.*\)')
        case $option in
            -h | --h | --help )
                help=1 ;;
            -v | --v | --verbose )
                verbose=--verbose ;;
            --podir )
                prev=podir ;;
            --podir=* )
                podir="$optarg" ;;
            --pot-header=* )
                pot_header="$optarg" ;;
            --skip-pot )
                skip_pot=1 ;;
            -* )
                error "unknown option $option"
                usage >&2
                exit 1 ;;
            * ) break ;;
        esac
        shift
done

if [ -n "$help" ]
then
        usage
        exit 0
fi

if [ -z "$podir" ]
then
        for d in debian/po po ../po
        do
                if [ -d $d ]
                then
                        podir=$d
                        break
                fi
        done
fi

if [ -z "$podir" ]
then
        die "No PO directory found; use --podir to specify location"
fi

if ! [ -d "$podir" ]
then
        die "PO directory $podir is not a directory"
fi

if ! [ -f "$podir/POTFILES.in" ]
then
        die "$podir/POTFILES.in does not exist"
fi

trace "PO directory is $podir"

cd "$podir"

if [ -f debian.pot ]
then
        domain=debian
else
        domain=templates
fi

if [ -z "$skip_pot" ]; then
        cmd="\"$PODEBCONF_LIB/intltool-update\" \"$verbose\" --gettext-package=\"$domain\" --pot"
        eval trace "$cmd"
        if ! eval $cmd
        then
                die "intltool-update failed"
        fi

        # Repair the header of the POT file if necessary.
        trace "\$pot_header is $pot_header"
        if [ -n "$pot_header" ]
        then
                repair_header "$pot_header" "$domain.pot"
        fi
else
        trace "skipping update of $domain.pot"
fi

for lang in *.po
do
        if [ "$lang" = "*.po" ]
        then
                break
        fi

        if sed -e '1,/^msgid/d' -e ':t /^msgstr/,${N;/\nmsgid/q;bt;};' "$lang" \
          | grep charset=CHARSET >/dev/null 2>&1; then
                echo "$podir/$lang: missing charset; file skipped" >&2
                continue
        fi

        lang=${lang%.po}
        "$PODEBCONF_LIB/intltool-update" --dist $verbose --gettext-package=$domain $lang || exit 1
done

rm -f messages.mo 2>/dev/null

# vim:set ai et sts=8 sw=8 tw=80: