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