]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - check-translations.sh
dccc1e8553845c67e4cd05b215e59ba6e4273db0
[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                         fi
58                         msgmerge -F -U "$X" "$VM".dat.pot >&2
59                         msgattrib --untranslated "$X" | grep . > "$X".untranslated || rm -f "$X".untranslated
60                         msgattrib --fuzzy "$X"        | grep . > "$X".fuzzy        || rm -f "$X".fuzzy
61                         nu=$((`grep -c ^#: "$X".untranslated 2>/dev/null` + 0))
62                         nf=$((`grep -c ^#: "$X".fuzzy        2>/dev/null` + 0))
63                         n=$(($nu + $nf))
64                         changed=false
65                         for Y in ~/check-translations/"$X".*; do
66                                 [ -f "$Y" ] || continue
67                                 vim -E "$Y" <<EOF
68 set fileencoding=utf-8
69 set nobomb
70 w
71 q
72 EOF
73                                 msgcat -F --use-first "$Y" "$X" > "$X".new
74                                 mv "$X".new "$X"
75                                 changed=true
76                         done
77                         nu0=$nu
78                         nf0=$nf
79                         if $changed; then
80                                 msgmerge -F -U "$X" "$VM".dat.pot >&2
81                                 msgattrib --untranslated "$X" | grep . > "$X".untranslated || rm -f "$X".untranslated
82                                 msgattrib --fuzzy "$X"        | grep . > "$X".fuzzy        || rm -f "$X".fuzzy
83                                 nu=$((`grep -c ^#: "$X".untranslated 2>/dev/null` + 0))
84                                 nf=$((`grep -c ^#: "$X".fuzzy        2>/dev/null` + 0))
85                                 n=$(($nu + $nf))
86                         fi
87                         if [ $n -gt 0 ]; then
88                                 echo "TODO for translation $X:"
89                                 echo "Untranslated: $nu (was: $nu0)"
90                                 echo "Fuzzy:        $nf (was: $nf0)"
91                                 ltr=`grep '^"Last-Translator: ' "$X" | cut -d ' ' -f 2- | cut -d '\\' -f 1 | egrep -v '<LL@li.org>|<EMAIL@ADDRESS>'`
92                                 ltm=`grep '^"Language-Team: ' "$X" | cut -d ' ' -f 2- | cut -d '\\' -f 1 | egrep -v '<LL@li.org>|<EMAIL@ADDRESS>'`
93                                 echo "Translators:  $ltr, $ltm"
94                                 case "$ltr" in
95                                         '')
96                                                 to=$ltm
97                                                 cc=
98                                                 ;;
99                                         *)
100                                                 to=$ltr
101                                                 if [ x"$ltr" = x"$ltm" ]; then
102                                                         cc=
103                                                 else
104                                                         cc=$ltm
105                                                 fi
106                                                 ;;
107                                 esac
108                                 if [ -n "$to" ]; then
109                                         echo "To:           $to"
110                                 fi
111                                 if [ -n "$cc" ]; then
112                                         echo "Cc:           $cc"
113                                 fi
114                                 if [ -n "$to" ]; then
115                                         while $mail; do
116                                                 echo "Send mail? [y/n]"
117                                                 read -r yesno
118                                                 case "$yesno" in
119                                                         y)
120                                                                 attach=
121                                                                 if [ $nu -gt 0 ]; then
122                                                                         attach="$attach $X.untranslated"
123                                                                 fi
124                                                                 if [ $nf -gt 0 ]; then
125                                                                         attach="$attach $X.fuzzy"
126                                                                 fi
127                                                                 {
128                                                                         cat <<EOF
129 Hi,
130
131 as you provided us with translations in the past, we kindly ask you
132 to update the translation to match changes in the Xonotic source. Can
133 you please work on them and provide updates to us?
134
135 If you do not wish to be contacted for translation updates any more,
136 please tell us in a reply to this message.
137
138 EOF
139                                                                         if [ $nu -gt 0 ]; then
140                                                                                 cat <<EOF
141 Attached to this message is a file
142 $X.untranslated
143 with $nu yet to be translated messages. Please translate them and reply
144 with the file containing the translations in the "msgstr" fields.
145
146 EOF
147                                                                         fi
148                                                                         if [ $nf -gt 0 ]; then
149                                                                                 cat <<EOF
150 Attached to this message is a file
151 $X.fuzzy
152 with $nf automatically generated translations. Please verify and/or fix
153 them and reply with the file having been verified by you.
154
155 EOF
156                                                                         fi
157                                                                         cat <<EOF
158 Thanks in advance,
159
160 Team Xonotic
161 EOF
162                                                                 } | mutt \
163                                                                         -e "set from=\"divVerent@xonotic.org\"" \
164                                                                         -e "set use_from=yes" \
165                                                                         -e "set use_envelope_from=yes" \
166                                                                         -s "Need update for translations: $X" \
167                                                                         -c "$cc" \
168                                                                         -b "admin@xonotic.org" \
169                                                                         -a $attach -- \
170                                                                         "$to"
171                                                                 break
172                                                                 ;;
173                                                         n)
174                                                                 break
175                                                                 ;;
176                                                 esac
177                                         done
178                                 fi
179                         fi
180                 done
181
182                 for X in "$VM".dat.*.po.disabled; do
183                         [ -f "$X" ] || continue
184                         if [ -n "$language" ]; then
185                                 if [ x"${X#*.dat.}" != x"$language.po" ]; then
186                                         continue
187                                 fi
188                         fi
189                         msgmerge -F -U "$X" "$VM".dat.pot >/dev/null 2>&1
190                 done
191         fi
192 done