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