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