forked from canonical/snapd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-pot
executable file
·92 lines (77 loc) · 2.61 KB
/
update-pot
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
#!/bin/sh
# -*- Mode: sh; indent-tabs-mode: t -*-
set -eu
# In LP#1758684 we got reports that the pot file generation
# is broken. To get to the bottom of this add checks here
# so that we error the build if this happens. Note that the
# strings may be update if those change but spread tests will
# tell us when it is needed.
check_canaries() {
c1="Alternative command to run"
c2="Name of the key to use, otherwise use the default key"
c3="too many arguments for command"
c4="%d days ago, at 15:04 MST"
for canary in "$c1" "$c2" "$c3" "$c4"; do
if ! grep -q "$canary" "$OUTPUT"; then
echo "canary '$canary' not found, pot extraction broken"
ls -lh "$OUTPUT"
exit 1
fi
done
}
HERE="$(readlink -f "$(dirname "$0")")"
OUTPUT="$HERE/po/snappy.pot"
if [ -n "${1:-}" ]; then
OUTPUT="$1"
fi
# ensure we have our xgettext-go
# shellcheck disable=SC2086
go install $GOINVOKEFLAGS github.com/snapcore/snapd/i18n/xgettext-go
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
# exclude vendor and _build subdir
find "$HERE" -type d \( -name "vendor" -o -name "_build" -o -name ".git" \) -prune -o -name "*.go" -type f -printf "%P\n" > "$tmpdir/go.files"
"${GOPATH%%:*}/bin/xgettext-go" \
-f "$tmpdir/go.files" \
-D "$HERE" \
-o "$OUTPUT" \
--add-comments-tag=TRANSLATORS: \
--sort-output \
--package-name=snappy\
--msgid-bugs-address=snappy-devel@lists.ubuntu.com \
--keyword=i18n.G \
--keyword-plural=i18n.NG
# check canary
check_canaries
sed -i 's/charset=CHARSET/charset=UTF-8/' "$OUTPUT"
find "$HERE" -path "$HERE/data/desktop/*.desktop.in" -type f -printf "%P\n" > "$tmpdir/desktop.files"
# we need the || true because Ubuntu 14.04's xgettext does not support
# extracting from desktop files.
xgettext \
-f "$tmpdir/desktop.files" \
-D "$HERE" \
-o "$OUTPUT" \
--language=Desktop \
--sort-output \
--package-name=snappy \
--msgid-bugs-address=snappy-devel@lists.ubuntu.com \
--join-existing || true
find "$HERE" -path "$HERE/data/polkit/*.policy" -type f -printf "%P\n" > "$tmpdir/polkit.files"
# we need the || true because of
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=891347
xgettext \
-f "$tmpdir/polkit.files" \
-D "$HERE" \
-o "$OUTPUT" \
--its="$HERE/po/its/polkit.its" \
--sort-output \
--package-name=snappy \
--msgid-bugs-address=snappy-devel@lists.ubuntu.com \
--join-existing || true
check_canaries
# language packs
for p in "${HERE}"/po/*.po; do
lang=$(basename "$p" .po)
mkdir -p "$HERE/share/locale/$lang/LC_MESSAGES"
msgfmt -v -o "$HERE/share/locale/$lang/LC_MESSAGES/snappy.mo" "$p"
done