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