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