Very minimalistic simplification of some code in ball/util.c.
[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 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 -i "0,/^$/ s/charset=CHARSET/charset=UTF-8/" "$POTFILE"
37
38 # Second, extract from neverball sets and neverputt courses
39 echo "# Sets and courses"
40 for i in $(< "$SETS"); do
41         i="$DATA"/"$i"
42
43         # Only translate the two first lines
44         head -2 $i | while read -r d; do
45                 echo
46                 echo "#: $i"
47                 # Convert \ to \\
48                 echo "msgid \"${d//\\/\\\\}\""
49                 echo "msgstr \"\""
50         done >> $POTFILE
51 done
52
53 # the "echo | cat x -" forces the end of the last line
54 echo | cat "$COURSES" - | while read -r d; do
55         # Heuristic: description is non empty line without .txt inside
56         if test -n "$d" && echo "$d" | grep -v ".txt" &> /dev/null; then
57                 echo
58                 echo "#: $COURSES"
59                 # Convert \ to \\
60                 echo "msgid \"${d//\\/\\\\}\""
61                 echo "msgstr \"\""
62         fi
63 done >> $POTFILE
64
65 # Third, extracts from levels
66 echo -n "# Levels: "
67 find "$DATA" -name "*.map" | sort | tee .map_list | wc -l
68 for i in `cat .map_list`; do
69         # Check encoding?
70         # file --mime $i
71         echo -n '.'
72         # Only translatable string is "message"
73         grep -E "^\"message\"" "$i" | while read -r a b; do
74                 echo
75                 echo "#: $i"
76                 echo "msgid ${b//\\/\\\\}"
77                 echo "msgstr \"\""
78         done >> $POTFILE
79 done
80 echo " ok"
81 rm .map_list
82
83 # Remove duplicates, to keep msgmerge from complaining
84 echo "# Removing duplicates."
85 msguniq -o "$POTFILE" -t UTF-8 "$POTFILE"
86