Substitute obsolete parameter in extractpo.
[neverball] / extractpo.sh
1 #!/bin/bash
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                
18 POTFILE="$1"
19 DOMAIN="$2"
20 COPYRIGHT="Robert Kooima"
21 BUGADDR="robert.kooima@gmail.com"
22
23 export LC_ALL=C
24
25 # First, extract from source
26 echo "# Sources"
27 > "$POTFILE"
28 xgettext --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]
29
30 # Force encoding to UTF-8
31 sed -i "0,/^$/ s/charset=CHARSET/charset=UTF-8/" "$POTFILE"
32
33 # Second, extract from neverball sets and neverputt courses
34 echo "# Sets and courses"
35 for i in $(< data/sets.txt); do
36         i=${i/#/data/}
37
38         # Only translate the two first lines
39         head -2 $i | while read -r d; do
40                 echo
41                 echo "#: $i"
42                 # Convert \ to \\ 
43                 echo "msgid \"${d//\\/\\\\}\""
44                 echo "msgstr \"\""
45         done >> $POTFILE
46 done
47
48 # the "echo | cat x -" forces the end of the last line
49 echo | cat data/courses.txt - | while read -r d; do
50         # Heuristic: description is non empty line without .txt inside
51         if test -n "$d" && echo "$d" | grep -v ".txt" &> /dev/null; then
52                 echo
53                 echo "#: data/courses.txt"
54                 # Convert \ to \\ 
55                 echo "msgid \"${d//\\/\\\\}\""
56                 echo "msgstr \"\""
57         fi
58 done >> $POTFILE
59
60 # Third, extracts from levels
61 echo -n "# Levels: "
62 find data -name "*.map" | sort | tee .map_list | wc -l
63 for i in `cat .map_list`; do
64         # Check encoding?
65         # file --mime $i
66         echo -n '.'
67         # Only translatable string is "message"
68         grep -E "^\"message\"" "$i" | while read -r a b; do
69                 echo
70                 echo "#: $i"
71                 echo "msgid ${b//\\/\\\\}"
72                 echo "msgstr \"\""
73         done >> $POTFILE
74 done
75 echo " ok"
76 rm .map_list
77
78 # Remove duplicates, to keep msgmerge from complaining
79 echo "# Removing duplicates."
80 msguniq -o "$POTFILE" -t UTF-8 "$POTFILE"
81