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