Merge remote-tracking branch 'origin/samual/serverlist'
[xonotic/xonotic-data.pk3dir.git] / check-translations.sh
1 #!/bin/sh
2
3 case "$1" in
4         pot)
5                 mode=pot
6                 mail=false
7                 ;;
8         po)
9                 mode=po
10                 mail=true
11                 language=$2
12                 ;;
13         '')
14                 echo "Sorry, you are not supposed to use this script."
15                 echo "This script is solely for use by the Xonotic Core Team."
16                 echo "Unauthorized use of it can cause HIGHLY annoying merge"
17                 echo "conflicts."
18                 exit 1
19                 ;;
20         *)
21                 mode=po
22                 mail=false
23                 language=$1
24                 ;;
25 esac
26
27 if [ x"$mode" = x"pot" ]; then
28         {
29                 find qcsrc -type f -name \*.\* -not -name \*.po -not -name \*.txt
30         } | xgettext -LC -k_ -f- --from-code utf-8 -F -o common.pot >&2
31 fi
32
33 if [ x"$mode" = x"po" ]; then
34         for X in common.*.po; do
35                 [ -f "$X" ] || continue
36                 if [ -n "$language" ]; then
37                         if [ x"${X#common.}" != x"$language.po" ]; then
38                                 continue
39                         fi
40                 else
41                         if [ x"${X#common.}" = x"en.po" ]; then
42                                 continue
43                         fi
44                 fi
45                 msgmerge -F -U "$X" common.pot >&2
46                 msgfmt -o /dev/null --check-format --check-header --use-fuzzy "$X" 2>&1 \
47                                               | grep . > "$X".errors       || rm -f "$X".errors
48                 msgattrib --untranslated "$X" | grep . > "$X".untranslated || rm -f "$X".untranslated
49                 msgattrib --fuzzy "$X"        | grep . > "$X".fuzzy        || rm -f "$X".fuzzy
50                 ne=$((`wc -l <     "$X".errors       2>/dev/null` + 0))
51                 nu=$((`grep -c ^#: "$X".untranslated 2>/dev/null` + 0))
52                 nf=$((`grep -c ^#: "$X".fuzzy        2>/dev/null` + 0))
53                 n=$(($ne + $nu + $nf))
54                 changed=false
55                 for Y in ~/check-translations/"$X".*; do
56                         [ -f "$Y" ] || continue
57                         echo "Merging $Y..."
58                         vim -E "$Y" <<EOF
59 set fileencoding=utf-8
60 set nobomb
61 w
62 q
63 EOF
64                         if ! msgcat "$Y" >/dev/null; then
65                                 echo "File $Y has syntax errors. Skipped."
66                                 continue
67                         fi
68                         msgcat -F --use-first "$Y" "$X" > "$X".new
69                         mv "$X".new "$X"
70                         changed=true
71                 done
72                 ne0=$ne
73                 nu0=$nu
74                 nf0=$nf
75                 if $changed; then
76                         msgfmt -o /dev/null --check-format --check-header --use-fuzzy "$X" 2>&1 \
77                                                       | grep . > "$X".errors       || rm -f "$X".errors
78                         msgattrib --untranslated "$X" | grep . > "$X".untranslated || rm -f "$X".untranslated
79                         msgattrib --fuzzy "$X"        | grep . > "$X".fuzzy        || rm -f "$X".fuzzy
80                         ne=$((`wc -l <     "$X".errors       2>/dev/null` + 0))
81                         nu=$((`grep -c ^#: "$X".untranslated 2>/dev/null` + 0))
82                         nf=$((`grep -c ^#: "$X".fuzzy        2>/dev/null` + 0))
83                         n=$(($ne + $nu + $nf))
84                 fi
85                 if [ $n -gt 0 ]; then
86                         echo "TODO for translation $X:"
87                         echo "Errors:       $ne (was: $ne0)"
88                         echo "Untranslated: $nu (was: $nu0)"
89                         echo "Fuzzy:        $nf (was: $nf0)"
90                         ltr=`grep '^"Last-Translator: ' "$X" | cut -d ' ' -f 2- | cut -d '\\' -f 1 | egrep -v '<LL@li.org>|<EMAIL@ADDRESS>'`
91                         ltm=`grep '^"Language-Team: ' "$X" | cut -d ' ' -f 2- | cut -d '\\' -f 1 | egrep -v '<LL@li.org>|<EMAIL@ADDRESS>'`
92                         echo "Translators:  $ltr, $ltm"
93                         case "$ltr" in
94                                 '')
95                                         to=$ltm
96                                         cc=
97                                         ;;
98                                 *)
99                                         to=$ltr
100                                         if [ x"$ltr" = x"$ltm" ]; then
101                                                 cc=
102                                         else
103                                                 cc=$ltm
104                                         fi
105                                         ;;
106                         esac
107                         if [ -n "$to" ]; then
108                                 echo "To:           $to"
109                         fi
110                         if [ -n "$cc" ]; then
111                                 echo "Cc:           $cc"
112                         fi
113                         if [ -n "$to" ]; then
114                                 while $mail; do
115                                         echo "Send mail? [y/n]"
116                                         read -r yesno
117                                         case "$yesno" in
118                                                 y)
119                                                         attach=
120                                                         if [ $ne -gt 0 ]; then
121                                                                 attach="$attach $X.errors"
122                                                         fi
123                                                         if [ $nu -gt 0 ]; then
124                                                                 attach="$attach $X.untranslated"
125                                                         fi
126                                                         if [ $nf -gt 0 ]; then
127                                                                 attach="$attach $X.fuzzy"
128                                                         fi
129                                                         {
130                                                                 cat <<EOF
131 Hi,
132
133 as you provided us with translations in the past, we kindly ask you
134 to update the translation to match changes in the Xonotic source. Can
135 you please work on them and provide updates to us?
136
137 For reference, the current version of the translation file is at:
138 http://git.xonotic.org/?p=xonotic/xonotic-data.pk3dir.git;a=blob;f=$X
139
140 If you do not wish to be contacted for translation updates any more,
141 please tell us in a reply to this message.
142
143 EOF
144                                                                 if [ $nu -gt 0 ]; then
145                                                                         cat <<EOF
146 Attached to this message is a file
147 $X.untranslated
148 with $nu yet to be translated messages. Please translate them and reply
149 with the file containing the translations in the "msgstr" fields.
150
151 EOF
152                                                                 fi
153                                                                 if [ $nf -gt 0 ]; then
154                                                                         cat <<EOF
155 Attached to this message is a file
156 $X.fuzzy
157 with $nf automatically generated translations. Please verify and/or fix
158 them and reply with the file having been verified by you.
159
160 EOF
161                                                                 fi
162                                                                 cat <<EOF
163 Thanks in advance,
164
165 Team Xonotic
166 EOF
167                                                         } | mutt \
168                                                                 -e "set from=\"divVerent@xonotic.org\"" \
169                                                                 -e "set use_from=yes" \
170                                                                 -e "set use_envelope_from=yes" \
171                                                                 -s "Need update for translations: $X" \
172                                                                 -c "$cc" \
173                                                                 -b "admin@xonotic.org" \
174                                                                 -a $attach -- \
175                                                                 "$to"
176                                                         break
177                                                         ;;
178                                                 n)
179                                                         break
180                                                         ;;
181                                         esac
182                                 done
183                         fi
184                 else
185                         echo "$X is complete!"
186                 fi
187         done
188
189         for X in common.*.po.disabled; do
190                 [ -f "$X" ] || continue
191                 if [ -n "$language" ]; then
192                         if [ x"${X#common.}" != x"$language.po" ]; then
193                                 continue
194                         fi
195                 fi
196                 msgmerge -F -U "$X" common.pot >/dev/null 2>&1
197         done
198 fi