msguniq in source:trunk/extractpo.sh to avoid msgmerge errors, as well as a
[neverball] / extractpo.sh
1 #!/bin/bash
2 # This program creates the neverball.pot file from source code and level files.
3
4 POTFILE="$1"
5 DOMAIN="$2"
6 COPYRIGHT="Robert Kooima"
7 BUGADDR="robert.kooima@gmail.com"
8
9 # First, extract from source
10 echo "# Sources"
11 > "$POTFILE"
12 xgettext --from-code=UTF-8 --keyword=_ --keyword=N_ -d "$DOMAIN" --copyright-holder="$COPYRIGHT" --msgid-bugs-address="$BUGADDR" -F -o "$POTFILE" ball/*.[ch] putt/*.[ch] share/*.[ch]
13
14 # Force encoding to UTF-8
15 sed -i "s/charset=CHARSET/charset=UTF-8/" "$POTFILE"
16
17 # Second, extract from neverball sets and neverputt courses
18 echo "# Sets and courses"
19 for i in data/sets.txt data/courses.txt; do
20         # the "echo | cat x -" forces the end of the last line
21         echo | cat "$i" - | while read -r d; do
22                 # Heuristic: description is non empty line without .txt inside
23                 if test -n "$d" && echo "$d" | grep -v ".txt" > /dev/null 2> /dev/null; then
24                         echo
25                         echo "#: $i"
26                         # Convert \ to \\ 
27                         echo "msgid \"${d//\\/\\\\}\""
28                         echo "msgstr \"\""
29                 fi
30         done >> $POTFILE
31 done
32
33 # Third, extracts from levels
34 echo "# Levels"
35 for i in `find data -name "*.map"`; do
36         # Check encoding?
37         # file --mime $i
38         
39         # Only translatable string is "message"
40         grep -E "^\"message\"" "$i" | while read -r a b; do
41                 echo
42                 echo "#: $i"
43                 echo "msgid ${b//\\/\\\\}"
44                 echo "msgstr \"\""
45         done >> $POTFILE
46 done
47
48 # Remove duplicates, to keep msgmerge from complaining
49 echo "Removing duplicates."
50 msguniq -o "$POTFILE" -t UTF-8 "$POTFILE"
51