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