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