Update hash
[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         txt)
9                 mode=txt
10                 mail=false
11                 ;;
12         po)
13                 mode=po
14                 mail=true
15                 language=$2
16                 ;;
17         '')
18                 echo "Sorry, you are not supposed to use this script."
19                 echo "This script is solely for use by the Xonotic Core Team."
20                 echo "Unauthorized use of it can cause HIGHLY annoying merge"
21                 echo "conflicts."
22                 exit 1
23                 ;;
24         *)
25                 mode=po
26                 mail=false
27                 language=$1
28                 ;;
29 esac
30
31 if [ x"$mode" = x"pot" ]; then
32         make QCC="../../../../gmqcc/gmqcc" clean
33         make QCC="../../../../gmqcc/gmqcc"
34         {
35                 grep -h '^\.' .tmp/*_includes.txt | cut -d ' ' -f 2 | sed -e 's,^,qcsrc/,' | while IFS= read -r name; do
36                         while :; do
37                                 case "$name" in
38                                         */./*)
39                                                 name=${name%%/./*}/${name#*/./}
40                                                 ;;
41                                         ./*)
42                                                 name=${name#./}
43                                                 ;;
44                                         */*/../*)
45                                                 before=${name%%/../*}
46                                                 before=${before%/*}
47                                                 name=$before/${name#*/../}
48                                                 ;;
49                                         */../*)
50                                                 name=${name#*/../}
51                                                 ;;
52                                         *)
53                                                 break
54                                                 ;;
55                                 esac
56                         done
57                         echo "$name"
58                 done | sort -u
59         } | xgettext -LC -k_ -f- --from-code utf-8 -F -o common.pot >&2
60 fi
61
62 if [ x"$mode" = x"txt" ]; then
63         {
64                 item=`grep "^en " languages.txt`
65                 echo "$item"
66                 for X in common.*.po; do
67                         [ -f "$X" ] || continue
68                         if [ -n "$language" ]; then
69                                 if [ x"${X#common.}" != x"$language.po" ]; then
70                                         continue
71                                 fi
72                         else
73                                 if [ x"${X#common.}" = x"en.po" ]; then
74                                         continue
75                                 fi
76                         fi
77                         po=`msgmerge -N "$X" common.pot`
78                         ne=`printf "%s\n" "$po" | msgfmt -o /dev/null --check-format --check-header --use-fuzzy - 2>&1 | grep . | wc -l`
79                         nu=`printf "%s\n" "$po" | msgattrib --untranslated - | grep -c ^#:`
80                         nf=`printf "%s\n" "$po" | msgattrib --fuzzy - | grep -c ^#:`
81                         nt=`printf "%s\n" "$po" | grep -c ^#:`
82                         n=$(($ne + $nu + $nf))
83                         p=$(( (nt - n) * 100 / nt ))
84                         echo >&2 "TODO for translation $X:"
85                         echo >&2 "Errors:       $ne"
86                         echo >&2 "Untranslated: $nu"
87                         echo >&2 "Fuzzy:        $nf"
88                         echo >&2 "Total:        $nt"
89                         echo >&2 "Percent:      $p"
90                         l=${X#common.}
91                         l=${l%.po}
92                         if ! item=`grep "^$l " languages.txt`; then
93                                 if [ "$p" -lt 50 ]; then
94                                         continue
95                                 fi
96                                 item="$l $l \"$l\" 0%"
97                         fi
98                         printf "%s\n" "$item" | sed -e "s/[0-9][0-9]*%/$p%/"
99                 done
100         } | tr '"' '\t' | sort -k3 | tr '\t' '"'
101 fi
102
103 if [ x"$mode" = x"po" ]; then
104         for X in common.*.po; do
105                 [ -f "$X" ] || continue
106                 if [ -n "$language" ]; then
107                         if [ x"${X#common.}" != x"$language.po" ]; then
108                                 continue
109                         fi
110                 else
111                         if [ x"${X#common.}" = x"en.po" ]; then
112                                 continue
113                         fi
114                 fi
115                 msgmerge -F -U "$X" common.pot >&2
116                 msgfmt -o /dev/null --check-format --check-header --use-fuzzy "$X" 2>&1 \
117                                               | grep . > "$X".errors       || rm -f "$X".errors
118                 msgattrib --untranslated "$X" | grep . > "$X".untranslated || rm -f "$X".untranslated
119                 msgattrib --fuzzy "$X"        | grep . > "$X".fuzzy        || rm -f "$X".fuzzy
120                 ne=$((`wc -l <     "$X".errors       2>/dev/null` + 0))
121                 nu=$((`grep -c ^#: "$X".untranslated 2>/dev/null` + 0))
122                 nf=$((`grep -c ^#: "$X".fuzzy        2>/dev/null` + 0))
123                 n=$(($ne + $nu + $nf))
124                 changed=false
125                 for Y in ~/check-translations/"$X".*; do
126                         [ -f "$Y" ] || continue
127                         echo "Merging $Y..."
128                         vim -E "$Y" <<EOF
129 set fileencoding=utf-8
130 set nobomb
131 w
132 q
133 EOF
134                         if ! msgcat "$Y" >/dev/null; then
135                                 echo "File $Y has syntax errors. Skipped."
136                                 continue
137                         fi
138                         msgcat -F --use-first "$Y" "$X" > "$X".new
139                         mv "$X".new "$X"
140                         changed=true
141                 done
142                 ne0=$ne
143                 nu0=$nu
144                 nf0=$nf
145                 if $changed; then
146                         msgfmt -o /dev/null --check-format --check-header --use-fuzzy "$X" 2>&1 \
147                                                       | grep . > "$X".errors       || rm -f "$X".errors
148                         msgattrib --untranslated "$X" | grep . > "$X".untranslated || rm -f "$X".untranslated
149                         msgattrib --fuzzy "$X"        | grep . > "$X".fuzzy        || rm -f "$X".fuzzy
150                         ne=$((`wc -l <     "$X".errors       2>/dev/null` + 0))
151                         nu=$((`grep -c ^#: "$X".untranslated 2>/dev/null` + 0))
152                         nf=$((`grep -c ^#: "$X".fuzzy        2>/dev/null` + 0))
153                         n=$(($ne + $nu + $nf))
154                 fi
155                 if [ $n -gt 0 ]; then
156                         echo "TODO for translation $X:"
157                         echo "Errors:       $ne (was: $ne0)"
158                         echo "Untranslated: $nu (was: $nu0)"
159                         echo "Fuzzy:        $nf (was: $nf0)"
160                         ltr=`grep '^"Last-Translator: ' "$X" | cut -d ' ' -f 2- | cut -d '\\' -f 1 | egrep -v '<LL@li.org>|<EMAIL@ADDRESS>'`
161                         ltm=`grep '^"Language-Team: ' "$X" | cut -d ' ' -f 2- | cut -d '\\' -f 1 | egrep -v '<LL@li.org>|<EMAIL@ADDRESS>'`
162                         echo "Translators:  $ltr, $ltm"
163                         case "$ltr" in
164                                 '')
165                                         to=$ltm
166                                         cc=
167                                         ;;
168                                 *)
169                                         to=$ltr
170                                         if [ x"$ltr" = x"$ltm" ]; then
171                                                 cc=
172                                         else
173                                                 cc=$ltm
174                                         fi
175                                         ;;
176                         esac
177                         if [ -n "$to" ]; then
178                                 echo "To:           $to"
179                         fi
180                         if [ -n "$cc" ]; then
181                                 echo "Cc:           $cc"
182                         fi
183                         if [ -n "$to" ]; then
184                                 while $mail; do
185                                         echo "Send mail? [y/n]"
186                                         read -r yesno
187                                         case "$yesno" in
188                                                 y)
189                                                         attach=
190                                                         if [ $ne -gt 0 ]; then
191                                                                 attach="$attach $X.errors"
192                                                         fi
193                                                         if [ $nu -gt 0 ]; then
194                                                                 attach="$attach $X.untranslated"
195                                                         fi
196                                                         if [ $nf -gt 0 ]; then
197                                                                 attach="$attach $X.fuzzy"
198                                                         fi
199                                                         {
200                                                                 cat <<EOF
201 Hi,
202
203 as you provided us with translations in the past, we kindly ask you
204 to update the translation to match changes in the Xonotic source. Can
205 you please work on them and provide updates to us?
206
207 For reference, the current version of the translation file is at:
208 http://git.xonotic.org/?p=xonotic/xonotic-data.pk3dir.git;a=blob;f=$X
209
210 If you do not wish to be contacted for translation updates any more,
211 please tell us in a reply to this message.
212
213 EOF
214                                                                 if [ $nu -gt 0 ]; then
215                                                                         cat <<EOF
216 Attached to this message is a file
217 $X.untranslated
218 with $nu yet to be translated messages. Please translate them and reply
219 with the file containing the translations in the "msgstr" fields.
220
221 EOF
222                                                                 fi
223                                                                 if [ $nf -gt 0 ]; then
224                                                                         cat <<EOF
225 Attached to this message is a file
226 $X.fuzzy
227 with $nf automatically generated translations. Please verify and/or fix
228 them and reply with the file having been verified by you.
229
230 EOF
231                                                                 fi
232                                                                 cat <<EOF
233 Thanks in advance,
234
235 Team Xonotic
236 EOF
237                                                         } | mutt \
238                                                                 -e "set from=\"divVerent@xonotic.org\"" \
239                                                                 -e "set use_from=yes" \
240                                                                 -e "set use_envelope_from=yes" \
241                                                                 -s "Need update for translations: $X" \
242                                                                 -c "$cc" \
243                                                                 -b "admin@xonotic.org" \
244                                                                 -a $attach -- \
245                                                                 "$to"
246                                                         break
247                                                         ;;
248                                                 n)
249                                                         break
250                                                         ;;
251                                         esac
252                                 done
253                         fi
254                 else
255                         echo "$X is complete!"
256                 fi
257         done
258
259         for X in common.*.po.disabled; do
260                 [ -f "$X" ] || continue
261                 if [ -n "$language" ]; then
262                         if [ x"${X#common.}" != x"$language.po" ]; then
263                                 continue
264                         fi
265                 fi
266                 msgmerge -F -U "$X" common.pot >/dev/null 2>&1
267         done
268 fi