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