update copyright info, also add a copiright template to add at the top of sourcefiles
[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 # First, extract from source
24 echo "# Sources"
25 > "$POTFILE"
26 xgettext --from-code=UTF-8 --keyword=_ --keyword=N_ --keyword=sgettext -d "$DOMAIN" --copyright-holder="$COPYRIGHT" --msgid-bugs-address="$BUGADDR" -F -o "$POTFILE" ball/*.[ch] putt/*.[ch] share/*.[ch]
27
28 # Force encoding to UTF-8
29 sed -i "s/charset=CHARSET/charset=UTF-8/" "$POTFILE"
30
31 # Second, extract from neverball sets and neverputt courses
32 echo "# Sets and courses"
33 for i in data/sets.txt data/courses.txt; do
34         # the "echo | cat x -" forces the end of the last line
35         echo | cat "$i" - | while read -r d; do
36                 # Heuristic: description is non empty line without .txt inside
37                 if test -n "$d" && echo "$d" | grep -v ".txt" > /dev/null 2> /dev/null; then
38                         echo
39                         echo "#: $i"
40                         # Convert \ to \\ 
41                         echo "msgid \"${d//\\/\\\\}\""
42                         echo "msgstr \"\""
43                 fi
44         done >> $POTFILE
45 done
46
47 # Third, extracts from levels
48 echo "# Levels"
49 for i in `find data -name "*.map"`; do
50         # Check encoding?
51         # file --mime $i
52         
53         # Only translatable string is "message"
54         grep -E "^\"message\"" "$i" | while read -r a b; do
55                 echo
56                 echo "#: $i"
57                 echo "msgid ${b//\\/\\\\}"
58                 echo "msgstr \"\""
59         done >> $POTFILE
60 done
61
62 # Remove duplicates, to keep msgmerge from complaining
63 echo "Removing duplicates."
64 msguniq -o "$POTFILE" -t UTF-8 "$POTFILE"
65