Rev Author Line No. Line
250 kaklik 1 #!/bin/sh
2 # $Id: sort_lang.sh,v 2.1 2003/11/26 20:42:58 nijel Exp $
3 ##
4 # Shell script to make each language file neat and tidy
5 #
6 # Robin Johnson <robbat2@users.sourceforge.net>
7 # August 9, 2002
8 ##
9  
10 specialsort()
11 {
12 in=$1
13 out=$2
14  
15 STRINGORDER="A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
16  
17 for i in $STRINGORDER;
18 do
19 egrep '^\$str'$i $in | sort >> $out
20 echo >> $out
21 done
22 }
23  
24 sortlang()
25 {
26 f=$1
27 targetdir=tmp-$f
28 mkdir -p $targetdir
29  
30 TRANSLATIONSTRING='//.*translate.*$'
31 STRINGSTRING='^\$str[[:alnum:]_]+'
32 WHITESPACE='^[[:blank:]]*$'
33 CVSID='/\* \$Id: sort_lang.sh,v 2.1 2003/11/26 20:42:58 nijel Exp $ \*/'
34  
35 echo -n "Extracting:"
36 echo -n " head"
37 egrep -i -v $TRANSLATIONSTRING $f | \
38 egrep -v "$STRINGSTRING|$CVSID|\?>|<\?php" >> $targetdir/head
39  
40 echo -n " cvs"
41 egrep "$CVSID" $f >>$targetdir/cvs
42  
43 echo -n " strings"
44 egrep -i -v "$WHITESPACE|$TRANSLATIONSTRING" $f | \
45 egrep $STRINGSTRING > $targetdir/tmp-tosort
46  
47 echo -n " pending_translations"
48 egrep -i "$STRINGSTRING.*$TRANSLATIONSTRING" $f > $targetdir/tmp-translate
49 echo
50  
51 echo -n "Building:"
52 echo -n " strings"
53 specialsort $targetdir/tmp-tosort $targetdir/sort
54  
55 echo -n " pending_translations"
56 if [ -s $targetdir/tmp-translate ] ; then
57 echo '// To translate:' > $targetdir/translate
58 specialsort $targetdir/tmp-translate $targetdir/translate
59 else
60 echo -n > $targetdir/translate
61 fi
62 echo
63  
64 echo "Assembling final"
65 echo "<?php" > $f
66 cat $targetdir/cvs $targetdir/head $targetdir/sort $targetdir/translate \
67 | uniq >> $f
68 echo "?>" >> $f
69  
70 rm -rf $targetdir
71 }
72  
73 echo "-------------------------------------------------------------------"
74 for i in "$@";
75 do
76 if [ ! -f $i ] ; then
77 echo "$i is not a file, skipping"
78 else
79 echo "Sorting $i"
80 sortlang $i
81 fi
82 echo "-------------------------------------------------------------------"
83 done;