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