-
Notifications
You must be signed in to change notification settings - Fork 0
/
numgettext.sh
84 lines (63 loc) · 2.05 KB
/
numgettext.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#! /bin/bash
POTFILES=$1
SRCDIR=$2
TMPFILE="nr.tmp"
TMP2="nr2.tmp"
DICT="nr.dic"
POT="nr.pot"
nl='
'
if [ -e $TMPFILE ]; then
ls $TMPFILE
fi
# Collect all function calls and assignments that possibly
# will be shown as warning or error.
for FILE in `cat $POTFILES`
do
if [ -e $SRCDIR/$FILE ]; then
grep -Pzo "error[^;/]*[^N]_\(\".*[^\\\]\"\)" $SRCDIR/$FILE >> $TMPFILE
grep -Pzo "warn[^;/]*[^N]_\(\".*[^\\\]\"\)" $SRCDIR/$FILE >> $TMPFILE
grep -Pzo '[^N]_\(\"((%[a-zA-Z]:?)+ )?(warning|error): ([^\"]|\\"|\"[^)])+\"\)' $SRCDIR/$FILE >> $TMPFILE
grep -Pzo "as_bad[^;/]*[^N]_\(\".*[^\\\]\"\)" $SRCDIR/$FILE >> $TMPFILE
grep -Pzo "fatal[^;/]*[^N]_\(\".*[^\\\]\"\)" $SRCDIR/$FILE >> $TMPFILE
fi;
done;
# Join broken lines
sed -i ':a;N;$!ba;s/\\\n//g' $TMPFILE
sed -i ':a;N;$!ba;s/\"\n\s\+\"//g' $TMPFILE
# Filter the lines that contains gettext function call.
grep -e "_(" $TMPFILE > $TMP2
mv $TMP2 $TMPFILE
# Strip the unneeded part around the text.
sed -i 's/.*_(\"\(\(\\\"\|[^"]\)*\)\")\?.*/\1/g' $TMPFILE
# Add exceptions that can not be found with grep.
if [ -e $SRCDIR/po/dictionary ]; then
cat $SRCDIR/po/dictionary >> $TMPFILE
fi;
# Remove multiplicated lines.
awk '!x[$0]++' $TMPFILE > $DICT
# Change \` to `
sed -i 's/\\`/`/g' $DICT
# Duplicate \ characters they would be solved othervise.
sed -i 's/\\/\\\\/g' $DICT
# Put the whole lines in quotes to keep whitespaces.
sed -i 's/^\(.*\)$/"\1"/g' $DICT
# Remove lines that contains %I format sequences.
# It is needed because .mo files which contain this kind of
# sequences have the major revision 1, that libintl can't handle.
sed -i 's/^.*%I.*$//g' $DICT
# Generate po format.
while read LINE
do
if [[ -n $LINE ]]
then
echo $nl >> $POT
echo "#: translation_for_numbering:1" >> $POT
echo "#, c-format" >> $POT
echo "msgid $LINE" >> $POT
echo "msgstr \"\"" >> $POT
fi
done < $DICT
# Duplicate backslash at \' and \%.
sed -i "s/\([^\]\)\([\]\)\(['%]\)/\1\2\2\3/g" $POT
#rm $DICT $TMPFILE