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