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 #grep "'$1'.*'$2'" $file | sed "s/.*\(GLOBALS.*('$1'.*'$2',\).*/\1/"| sort -u | while read oldstrn
50 grep "'$1'.*'$2'" $file | sed "s/.*\(GLOBALS\['Language'\].[^(]*('$1'.*'$2',\).*/\1/"| sort -u | while read oldstrn
52 #echo "== \$$oldstrn ==> $newstrn =="
53 substitute "$oldstrn" "$newstrn" "$3"
57 newstrn="gettext(\"$strn\")"
58 #grep "'$1'.*'$2'" $file | sed "s/.*\(GLOBALS.*('$1'.*'$2')\).*/\1/"| sort -u | while read oldstrn
59 grep "'$1'.*'$2'" $file | sed "s/.*\(GLOBALS\['Language'\].[^(]*('$1'.*'$2')\).*/\1/"| sort -u | while read oldstrn
61 #echo "== \$$oldstrn ==> $newstrn =="
62 substitute "$oldstrn" "$newstrn" "$3"
69 echo "ERROR translation found several time in $3 for"
70 echo "------------------------------------"
71 grep "$1 $2 " alltab.txt
72 echo "------------------------------------"
77 if [ ! -f alltab.txt ]
79 readallentab > alltab.txt
80 # I have to double backquote to have this working, probably because of shell interaction
81 perl -pi -e 's/"/\\\\"/g' alltab.txt
88 echo "Copying tree in $target"
89 find . | grep -v '/.svn' | cpio -pdumvB $target
92 find $target -name "*.php" | grep -v '/.svn' | while read file
95 #grep "getText(" $file | sed "s/.*getText.[^']*'\(.[^']*\)'.[^']*'\(.[^']*\)'.*/\1 \2/g" | while read key1 key2
96 #grep "getText(" $file | sed "s/.*getText('\(.[^']*\)'.[^']*'\(.[^']*\)'.*/\1 \2/g" | while read key1 key2
98 perl -pi -e "s{\\QLanguage->getText\\E}{GLOBALS['Language']->getText}sg" $file
100 #grep "getText('.[^']*'.[^']*'.[^']*'.*" $file | sed "s/.*getText('\(.[^']*\)'.[^']*'\(.[^']*\)'.*/\1 \2/g" | while read key1 key2
101 grep "GLOBALS\['Language'\]->getText('.[^']*'.[^']*'.[^']*'.*" $file | sed "s/.*GLOBALS\['Language'\]->getText('\(.[^']*\)'.[^']*'\(.[^']*\)'.*/\1 \2/g" | while read key1 key2
103 if [ "$found" = "0" ]
105 echo "======== $file ========"
108 decode $key1 $key2 $file
111 if [ "$found" = "1" ]
113 php -l $file | grep -v "No syntax errors detected"