forked from mopsfelder/network-manager-openconnect
-
Notifications
You must be signed in to change notification settings - Fork 13
/
import-strings.sh
117 lines (104 loc) · 3.93 KB
/
import-strings.sh
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
#!/bin/sh
if [ "$OPENCONNECT_DIR" = "" ]; then
OPENCONNECT_DIR=../openconnect
fi
if [ "$OPENCONNECT_BUILD_DIR" = "" ]; then
OPENCONNECT_BUILD_DIR="$OPENCONNECT_DIR"
fi
# The openconnect.pot file is made available by a cron job on this server, along
# with the project's web site which is also held in the git repository. There's
# race condition here, if the server is updating as we run this script. But it's
# unlikely that the string in question would move far, so it should be good enough.
COMMIT="$(cd $OPENCONNECT_DIR && git rev-parse HEAD)"
if ! echo $COMMIT | egrep -q "[a-f0-9]{40}"; then
echo "Error: Failed to fetch commit ID from $OPENCONNECT_DIR"
exit 1
fi
pushd $OPENCONNECT_BUILD_DIR
make po/openconnect.pot || exit 1
popd
COMMIT=$(echo $COMMIT | cut -c1-10)
GITWEB=https://git.infradead.org/users/dwmw2/openconnect.git/blob/${COMMIT}:/
OUTFILE=openconnect-strings-$COMMIT.txt
cat >$OUTFILE <<EOF
This file contains strings from the OpenConnect VPN client, found at
https://www.infradead.org/openconnect/ and browsable in gitweb at
https://git.infradead.org/users/dwmw2/openconnect.git
We do this because NetworkManager-openconnect authentication dialog
uses a lot of strings from libopenconnect, which also need to be
translated too if the user is to have a fully localised experience.
For translators looking to see source comments in their original context
in order to translate them properly, the URLs by each one will give a
link to the original source code.
EOF
cat $OPENCONNECT_BUILD_DIR/po/openconnect.pot |
while read -r line; do
case "$line" in
"#:"*)
echo >>$OUTFILE
# FIXME: If it was already in openconnect-strings.txt can we keep the
# previous URL instead of using the latest commit, to reduce churn?
for src in ${line###: }; do
echo "// ${GITWEB}${src%%:*}#l${src##*:}" >>$OUTFILE
done
real_strings=yes
;;
"msgid "*)
if [ "$real_strings" = "yes" ]; then
echo -n "_(${line##msgid }" >>$OUTFILE
in_msgid=yes
fi
;;
"msgstr "*|"")
if [ "$in_msgid" = "yes" ]; then
in_msgid=no
echo ");" >>$OUTFILE
fi
;;
*)
if [ "$in_msgid" = "yes" ]; then
echo >>$OUTFILE
echo -n "$line" >>$OUTFILE
fi
;;
esac
done
MESSAGES=$(grep -c "^_(" openconnect-strings-$COMMIT.txt)
echo "Got $MESSAGES messages from openconnect upstream"
if [ "$MESSAGES" -lt 100 ]; then
echo "Fewer than 100 messages? Something went wrong"
rm openconnect-strings-$COMMIT.txt
exit 1
fi
NEWSHA=$(grep -v ^// openconnect-strings-$COMMIT.txt | sha1sum)
OLDSHA=$(grep -v ^// openconnect-strings.txt | sha1sum)
if [ "$NEWSHA" != "$OLDSHA" ]; then
echo New strings
mv openconnect-strings-$COMMIT.txt openconnect-strings.txt
else
echo No new strings. Not changing openconnect-strings.txt
rm openconnect-strings-$COMMIT.txt
fi
make -C po NetworkManager-openconnect.pot || exit 1
for a in po/*.po ; do
echo Comparing $a...
if [ -r $OPENCONNECT_DIR/$a ]; then
msgattrib -F --no-fuzzy $OPENCONNECT_DIR/$a > $a.openconnect 2>/dev/null
msgmerge -q -N -F $a -C $a.openconnect po/NetworkManager-openconnect.pot > $a.merged
msgmerge -q -N -F $a po/NetworkManager-openconnect.pot > $a.unmerged
if ! cmp $a.merged $a.unmerged; then
echo New changes for $a
mv $a.merged $a
fi
rm -f $a.openconnect $a.merged $a.unmerged
msgattrib -F --no-fuzzy $a > $a.nmo
msgmerge -q -N -C $OPENCONNECT_DIR/$a -F $a.nmo $OPENCONNECT_BUILD_DIR/po/openconnect.pot > $OPENCONNECT_DIR/$a.merged1
msgattrib -F --no-fuzzy --no-obsolete $OPENCONNECT_DIR/$a.merged1 > $OPENCONNECT_DIR/$a.merged2
msgmerge -q -N -F $OPENCONNECT_DIR/$a $OPENCONNECT_BUILD_DIR/po/openconnect.pot > $OPENCONNECT_DIR/$a.unmerged
if ! cmp $OPENCONNECT_DIR/$a.merged2 $OPENCONNECT_DIR/$a.unmerged; then
echo New changes for OpenConnect $a
mv $OPENCONNECT_DIR/$a.merged2 $OPENCONNECT_DIR/$a
fi
rm -f $OPENCONNECT_DIR/$a.merged2 $OPENCONNECT_DIR/$a.merged1 $OPENCONNECT_DIR/$a.unmerged $a.nmo
fi
done