Changed config_user_path to check the APPDATA environment variable under
[neverball] / extractpo.sh
1 #!/bin/sh
2 # This program creates the neverball.pot file from source code and level files.
3
4 # Copyright (C) 2006 Jean Privat
5 # Part of the Neverball Project http://icculus.org/neverball/
6 #
7 # NEVERBALL is  free software; you can redistribute  it and/or modify
8 # it under the  terms of the GNU General  Public License as published
9 # by the Free  Software Foundation; either version 2  of the License,
10 # or (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
14 # MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
15 # General Public License for more details.
16
17 set -B
18
19 POTFILE="$1"
20 DOMAIN="$2"
21 COPYRIGHT="Robert Kooima"
22 BUGADDR="robert.kooima@gmail.com"
23
24 DATA=data
25 SETS="$DATA"/sets.txt
26 COURSES="$DATA"/courses.txt
27
28 export LC_ALL=C
29
30 # First, extract from source
31 echo "# Sources"
32 > "$POTFILE"
33 xgettext --add-comments=TRANSLATORS --from-code=UTF-8 --keyword=_ --keyword=N_ --keyword=sgettext -d "$DOMAIN" --copyright-holder="$COPYRIGHT" --msgid-bugs-address="$BUGADDR" -F -o "$POTFILE" {ball,putt,share}/*.[ch]
34
35 # Force encoding to UTF-8
36 sed "1,/^$/ s/charset=CHARSET/charset=UTF-8/" < "$POTFILE" > "$POTFILE".utf8
37 mv "$POTFILE".utf8 "$POTFILE"
38
39 # Second, extract from neverball sets and neverputt courses
40 echo "# Sets and courses"
41 for i in $(cat "$SETS"); do
42         i="$DATA"/"$i"
43
44         # Only translate the two first lines
45         head -2 $i | while read -r d; do
46                 echo
47                 echo "#: $i"
48                 # Convert \ to \\
49                 echo "msgid \"$(echo "$d" | sed 's/\\/\\\\/g')\""
50                 echo "msgstr \"\""
51         done >> $POTFILE
52 done
53
54 # the "echo | cat x -" forces the end of the last line
55 echo | cat "$COURSES" - | while read -r d; do
56         # Heuristic: description is non empty line without .txt inside
57         if test -n "$d" && echo "$d" | grep -v ".txt" &> /dev/null; then
58                 echo
59                 echo "#: $COURSES"
60                 # Convert \ to \\
61                 echo "msgid \"$(echo "$d" | sed 's/\\/\\\\/g')\""
62                 echo "msgstr \"\""
63         fi
64 done >> $POTFILE
65
66 # Third, extracts from levels
67 echo -n "# Levels: "
68 find "$DATA" -name "*.map" | sort | tee .map_list | wc -l
69 for i in $(cat .map_list); do
70         # Check encoding?
71         # file --mime $i
72         echo -n '.'
73         # Only translatable string is "message"
74         grep -E "^\"message\"" "$i" | while read -r a b; do
75                 echo
76                 echo "#: $i"
77                 echo "msgid $(echo "$b" | sed 's/\\/\\\\/g')"
78                 echo "msgstr \"\""
79         done >> $POTFILE
80 done
81 echo " ok"
82 rm .map_list
83
84 # Remove duplicates, to keep msgmerge from complaining
85 echo "# Removing duplicates."
86 msguniq -o "$POTFILE" -t UTF-8 "$POTFILE"
87