]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - check-translations.sh
ignore en.po by default
[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                                 if ! msgcat "$Y" >/dev/null; then
72                                         echo "File $Y has syntax errors. Skipped."
73                                         continue
74                                 fi
75                                 echo "Merging $Y..."
76                                 vim -E "$Y" <<EOF
77 set fileencoding=utf-8
78 set nobomb
79 w
80 q
81 EOF
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 If you do not wish to be contacted for translation updates any more,
145 please tell us in a reply to this message.
146
147 EOF
148                                                                         if [ $nu -gt 0 ]; then
149                                                                                 cat <<EOF
150 Attached to this message is a file
151 $X.untranslated
152 with $nu yet to be translated messages. Please translate them and reply
153 with the file containing the translations in the "msgstr" fields.
154
155 EOF
156                                                                         fi
157                                                                         if [ $nf -gt 0 ]; then
158                                                                                 cat <<EOF
159 Attached to this message is a file
160 $X.fuzzy
161 with $nf automatically generated translations. Please verify and/or fix
162 them and reply with the file having been verified by you.
163
164 EOF
165                                                                         fi
166                                                                         cat <<EOF
167 Thanks in advance,
168
169 Team Xonotic
170 EOF
171                                                                 } | mutt \
172                                                                         -e "set from=\"divVerent@xonotic.org\"" \
173                                                                         -e "set use_from=yes" \
174                                                                         -e "set use_envelope_from=yes" \
175                                                                         -s "Need update for translations: $X" \
176                                                                         -c "$cc" \
177                                                                         -b "admin@xonotic.org" \
178                                                                         -a $attach -- \
179                                                                         "$to"
180                                                                 break
181                                                                 ;;
182                                                         n)
183                                                                 break
184                                                                 ;;
185                                                 esac
186                                         done
187                                 fi
188                         fi
189                 done
190
191                 for X in "$VM".dat.*.po.disabled; do
192                         [ -f "$X" ] || continue
193                         if [ -n "$language" ]; then
194                                 if [ x"${X#*.dat.}" != x"$language.po" ]; then
195                                         continue
196                                 fi
197                         fi
198                         msgmerge -F -U "$X" "$VM".dat.pot >/dev/null 2>&1
199                 done
200         fi
201 done