3 # This file is used to convert $GLOBALS['Language']->getText('str1','str2') to gettext("English String from tab(str1,str2)")
4 # Copyright Christian Bayle <bayle@debian.org> 2009
5 # Licenced as GPL v2 or next or Affero GPL to your courtesy
6 # Thanks to PK for perl regexp help
8 # Interesting part is to point non translatable strings, that should maybe be modified before operation
9 # not sure it is useable as is as in only replace strings for english.
10 # May be interesting to use in conjunction with Novaforge tab2po
13 # Just run in trunk dir, translated repository will be in ../trunk.gettext
17 find . -name "*.tab" | grep -v '.svn' | grep en_US | xargs cat
18 find . -name "Base.tab" | grep -v '.svn' | xargs cat
25 #perl -e print quotemeta "$2"
26 #echo "Converting in $3"
27 echo "+++ $var1 ==> $var2 +++"
28 #perl -pi -e "s/$var1/$var2/g" $3
29 #perl -pi -e "s{$var1}{$var2}go" $3
30 perl -pi -e "s{$var1}{$var2}sg" $3
35 count=`grep "$1 $2 " alltab.txt | wc -l`
38 echo "ERROR: translation not found in $3 for:"
39 echo "------------------------------------"
41 echo "------------------------------------"
44 strn="`grep \"$1 $2 \" alltab.txt | cut -d' ' -f3`"
47 strns=`echo "$strn" | sed 's/\$./%s/g'`
48 # newstrn="gettext(\"$strns\","
49 newstrn="gettext(\"$strns\""
50 #grep "'$1'.*'$2'" $file | sed "s/.*\(GLOBALS.*('$1'.*'$2',\).*/\1/"| sort -u | while read oldstrn
51 #grep "'$1'.*'$2'" $file | sed "s/.*\(GLOBALS\['Language'\]->getText('$1'.[^']*'$2',\).*/\1/"| sort -u | while read oldstrn
53 grep "'$1'.*'$2'" $file | sed "s/.*\(GLOBALS\['Language'\]->getText('$1'.[^']*'$2'\).*/\1/"| sort -u | while read oldstrn
55 echo "==TOMANUALCONVERT \$$oldstrn ==> $newstrn =="
56 #substitute "$oldstrn" "$newstrn" "$3"
61 # newstrn="gettext(\"$strn\")"
62 newstrn="gettext(\"$strn\""
63 #grep "'$1'.*'$2'" $file | sed "s/.*\(GLOBALS.*('$1'.*'$2')\).*/\1/"| sort -u | while read oldstrn
64 #grep "'$1'.*'$2'" $file | sed "s/.*\(GLOBALS\['Language'\]->getText('$1'.[^']*'$2')\).*/\1/"| sort -u | while read oldstrn
66 grep "'$1'.*'$2'" $file | sed "s/.*\(GLOBALS\['Language'\]->getText('$1'.[^']*'$2'\).*/\1/"| sort -u | while read oldstrn
68 #echo "== \$$oldstrn ==> $newstrn =="
69 substitute "$oldstrn" "$newstrn" "$3"
77 echo "ERROR translation found several time in $3 for"
78 echo "------------------------------------"
79 grep "$1 $2 " alltab.txt
80 echo "------------------------------------"
85 if [ ! -f alltab.txt ]
87 readallentab > alltab.txt
88 # I have to double backquote to have this working, probably because of shell interaction
89 perl -pi -e 's/"/\\\\"/g' alltab.txt
96 echo "Copying tree in $target"
97 find . | grep -v '/.svn' | cpio -pdumvB $target
100 find $target -name "*.php" | grep -v '/.svn' | while read file
103 #grep "getText(" $file | sed "s/.*getText.[^']*'\(.[^']*\)'.[^']*'\(.[^']*\)'.*/\1 \2/g" | while read key1 key2
104 #grep "getText(" $file | sed "s/.*getText('\(.[^']*\)'.[^']*'\(.[^']*\)'.*/\1 \2/g" | while read key1 key2
106 perl -pi -e "s{\\QLanguage->getText\\E}{GLOBALS['Language']->getText}sg" $file
108 #grep "getText('.[^']*'.[^']*'.[^']*'.*" $file | sed "s/.*getText('\(.[^']*\)'.[^']*'\(.[^']*\)'.*/\1 \2/g" | while read key1 key2
109 grep "GLOBALS\['Language'\]->getText('.[^']*'.[^']*'.[^']*'.*" $file | sed "s/.*GLOBALS\['Language'\]->getText('\(.[^']*\)'.[^']*'\(.[^']*\)'.*/\1 \2/g" | while read key1 key2
111 if [ "$found" = "0" ]
113 echo "======== $file ========"
116 echo "-- $key1 -- $key2 --"
117 decode $key1 $key2 $file
119 if [ "$found" = "1" ]
121 php -l $file | grep -v "No syntax errors detected"