]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - check-translations.sh
Merge branch 'master' into terencehill/itemstime
[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         po)
9                 mode=po
10                 mail=true
11                 language=$2
12                 ;;
13         '')
14                 echo "Sorry, you are not supposed to use this script."
15                 echo "This script is solely for use by the Xonotic Core Team."
16                 echo "Unauthorized use of it can cause HIGHLY annoying merge"
17                 echo "conflicts."
18                 exit 1
19                 ;;
20         *)
21                 mode=po
22                 mail=false
23                 language=$1
24                 ;;
25 esac
26
27 for VM in menu csprogs; do
28         case "$VM" in
29                 csprogs)
30                         VMD=client
31                         ;;
32                 *)
33                         VMD=$VM
34                         ;;
35         esac
36
37         if [ x"$mode" = x"pot" ]; then
38                 {
39                         find qcsrc/"$VMD" -type f -not -name \*.po -not -name \*.txt
40                         find qcsrc/common -type f -not -name \*.po -not -name \*.txt
41                         if [ x"$VM" = x"csprogs" ]; then
42                                 find qcsrc/server -type f -name w_\*.qc
43                         elif [ x"$VM" = x"menu" ]; then
44                                 find qcsrc/server -type f -name w_\*.qc | xargs grep ^REGISTER_WEAPON > weapons.qc.tmp
45                                 echo "weapons.qc.tmp"
46                         fi
47                 } | xgettext -LC -k_ -f- --from-code utf-8 -o "$VM".dat.pot >&2
48         fi
49
50         if [ x"$mode" = x"po" ]; then
51                 for X in "$VM".dat.*.po; do
52                         [ -f "$X" ] || continue
53                         if [ -n "$language" ]; then
54                                 if [ x"${X#*.dat.}" != x"$language.po" ]; then
55                                         continue
56                                 fi
57                         else
58                                 if [ x"${X#*.dat.}" = x"en.po" ]; then
59                                         continue
60                                 fi
61                         fi
62                         msgmerge -F -U "$X" "$VM".dat.pot >&2
63                         msgattrib --untranslated "$X" | grep . > "$X".untranslated || rm -f "$X".untranslated
64                         msgattrib --fuzzy "$X"        | grep . > "$X".fuzzy        || rm -f "$X".fuzzy
65                         nu=$((`grep -c ^#: "$X".untranslated 2>/dev/null` + 0))
66                         nf=$((`grep -c ^#: "$X".fuzzy        2>/dev/null` + 0))
67                         n=$(($nu + $nf))
68                         changed=false
69                         for Y in ~/check-translations/"$X".*; do
70                                 [ -f "$Y" ] || continue
71                                 echo "Merging $Y..."
72                                 vim -E "$Y" <<EOF
73 set fileencoding=utf-8
74 set nobomb
75 w
76 q
77 EOF
78                                 if ! msgcat "$Y" >/dev/null; then
79                                         echo "File $Y has syntax errors. Skipped."
80                                         continue
81                                 fi
82                                 msgcat -F --use-first "$Y" "$X" > "$X".new
83                                 mv "$X".new "$X"
84                                 changed=true
85                         done
86                         nu0=$nu
87                         nf0=$nf
88                         if $changed; then
89                                 msgmerge -F -U "$X" "$VM".dat.pot >&2
90                                 msgattrib --untranslated "$X" | grep . > "$X".untranslated || rm -f "$X".untranslated
91                                 msgattrib --fuzzy "$X"        | grep . > "$X".fuzzy        || rm -f "$X".fuzzy
92                                 nu=$((`grep -c ^#: "$X".untranslated 2>/dev/null` + 0))
93                                 nf=$((`grep -c ^#: "$X".fuzzy        2>/dev/null` + 0))
94                                 n=$(($nu + $nf))
95                         fi
96                         if [ $n -gt 0 ]; then
97                                 echo "TODO for translation $X:"
98                                 echo "Untranslated: $nu (was: $nu0)"
99                                 echo "Fuzzy:        $nf (was: $nf0)"
100                                 ltr=`grep '^"Last-Translator: ' "$X" | cut -d ' ' -f 2- | cut -d '\\' -f 1 | egrep -v '<LL@li.org>|<EMAIL@ADDRESS>'`
101                                 ltm=`grep '^"Language-Team: ' "$X" | cut -d ' ' -f 2- | cut -d '\\' -f 1 | egrep -v '<LL@li.org>|<EMAIL@ADDRESS>'`
102                                 echo "Translators:  $ltr, $ltm"
103                                 case "$ltr" in
104                                         '')
105                                                 to=$ltm
106                                                 cc=
107                                                 ;;
108                                         *)
109                                                 to=$ltr
110                                                 if [ x"$ltr" = x"$ltm" ]; then
111                                                         cc=
112                                                 else
113                                                         cc=$ltm
114                                                 fi
115                                                 ;;
116                                 esac
117                                 if [ -n "$to" ]; then
118                                         echo "To:           $to"
119                                 fi
120                                 if [ -n "$cc" ]; then
121                                         echo "Cc:           $cc"
122                                 fi
123                                 if [ -n "$to" ]; then
124                                         while $mail; do
125                                                 echo "Send mail? [y/n]"
126                                                 read -r yesno
127                                                 case "$yesno" in
128                                                         y)
129                                                                 attach=
130                                                                 if [ $nu -gt 0 ]; then
131                                                                         attach="$attach $X.untranslated"
132                                                                 fi
133                                                                 if [ $nf -gt 0 ]; then
134                                                                         attach="$attach $X.fuzzy"
135                                                                 fi
136                                                                 {
137                                                                         cat <<EOF
138 Hi,
139
140 as you provided us with translations in the past, we kindly ask you
141 to update the translation to match changes in the Xonotic source. Can
142 you please work on them and provide updates to us?
143
144 For reference, the current version of the translation file is at:
145 http://git.xonotic.org/?p=xonotic/xonotic-data.pk3dir.git;a=blob;f=$X
146
147 If you do not wish to be contacted for translation updates any more,
148 please tell us in a reply to this message.
149
150 EOF
151                                                                         if [ $nu -gt 0 ]; then
152                                                                                 cat <<EOF
153 Attached to this message is a file
154 $X.untranslated
155 with $nu yet to be translated messages. Please translate them and reply
156 with the file containing the translations in the "msgstr" fields.
157
158 EOF
159                                                                         fi
160                                                                         if [ $nf -gt 0 ]; then
161                                                                                 cat <<EOF
162 Attached to this message is a file
163 $X.fuzzy
164 with $nf automatically generated translations. Please verify and/or fix
165 them and reply with the file having been verified by you.
166
167 EOF
168                                                                         fi
169                                                                         cat <<EOF
170 Thanks in advance,
171
172 Team Xonotic
173 EOF
174                                                                 } | mutt \
175                                                                         -e "set from=\"divVerent@xonotic.org\"" \
176                                                                         -e "set use_from=yes" \
177                                                                         -e "set use_envelope_from=yes" \
178                                                                         -s "Need update for translations: $X" \
179                                                                         -c "$cc" \
180                                                                         -b "admin@xonotic.org" \
181                                                                         -a $attach -- \
182                                                                         "$to"
183                                                                 break
184                                                                 ;;
185                                                         n)
186                                                                 break
187                                                                 ;;
188                                                 esac
189                                         done
190                                 fi
191                         else
192                                 echo "$X is complete!"
193                         fi
194                 done
195
196                 for X in "$VM".dat.*.po.disabled; do
197                         [ -f "$X" ] || continue
198                         if [ -n "$language" ]; then
199                                 if [ x"${X#*.dat.}" != x"$language.po" ]; then
200                                         continue
201                                 fi
202                         fi
203                         msgmerge -F -U "$X" "$VM".dat.pot >/dev/null 2>&1
204                 done
205         fi
206 done