[Fusionforge-commits] r7899 - trunk/tools

Christian Bayle cbayle at libremir.placard.fr.eu.org
Thu Jun 25 22:20:39 CEST 2009


Author: cbayle
Date: 2009-06-25 22:20:38 +0200 (Thu, 25 Jun 2009)
New Revision: 7899

Modified:
   trunk/tools/tab2gettext.pl
Log:
Add verbosity, better deal with args


Modified: trunk/tools/tab2gettext.pl
===================================================================
--- trunk/tools/tab2gettext.pl	2009-06-24 22:38:27 UTC (rev 7898)
+++ trunk/tools/tab2gettext.pl	2009-06-25 20:20:38 UTC (rev 7899)
@@ -4,6 +4,7 @@
 use warnings;
 
 my %tab;
+my $verbose=10;
 
 sub findtxt2 {
 	my $key1 = shift;
@@ -17,35 +18,39 @@
 	my $key2 = shift;
 	my $extra = shift;
 	my $txt = $tab{$key1}{$key2};
-	my $txtsave = $tab{$key1}{$key2};
+	my $txtsave = $txt;
 	my @key = split /\$/, "$txt";
 	if ( @key == 2 ){
-		if ($txt =~ s/\$./\%\s/g){
-			return "vsprintf(_(\"$txt\"), $extra)";
-		} else {
-			return "TOCHECKvsprintf(_(\"$txtsave\"), $extra)";
-		}
+		$txt =~ s/\$./\%s/g;
+		return "vsprintf(_(\"$txt\"), $extra)";
+	} else {
+		return "TOCHECKvsprintf(_(\"$txtsave\"), $extra)";
 	}
 }
 
-print "Reading alltab.txt\n-------------\n";
-open(FILE, "<", "alltab.txt") or die "Can't open alltab.txt: $!";
-while (<FILE>){
-	if(/(.[^	]*)	(.[^	]*)	(.*)/){
-		$tab{"$1"}{"$2"}="$3";
+sub readalltab {
+	if ($verbose > 1) {print "Reading alltab.txt\n"};
+	open(FILE, "<", "alltab.txt") or die "Can't open alltab.txt: $!";
+	my $re = "^(.[^	]*)	(.[^	]*)	(.*)";
+	while (<FILE>){
+		if(/$re/){
+			$tab{"$1"}{"$2"}="$3";
+		}
 	}
+	close(FILE);
+	return %tab;
 }
-close(FILE);
 
 
-print "Reading $ARGV[0]\n-------------\n";
-open(FILE, "<", $ARGV[0]) or die "Can't open $ARGV[0]: $!";
-binmode FILE;
-my ($buf, $data, $n); while (($n = read FILE, $data, 1000000) != 0) { print "$n bytes read\n"; $buf .= $data; } close(FILE); 
+sub tab2gettextfile {
+	my $filename = shift;
+	open(FILE, "<", $filename) or die "Can't open $filename: $!";
+	binmode FILE;
+	my ($buf, $data, $n); while (($n = read FILE, $data, 1000000) != 0) {if($verbose > 5){print "$n bytes read\n"}; $buf .= $data; } close(FILE); 
 
-$buf =~ s{\QLanguage->getText\E}{GLOBALS['Language']->getText}sg;
+	$buf =~ s{\QLanguage->getText\E}{GLOBALS['Language']->getText}sg;
 
-my $re = qr{ (                    # paren group 1 (full function)
+	my $re = qr{ (                    # paren group 1 (full function)
               \QGLOBALS['Language']->getText\E
                (                  # paren group 2 (parens)
                 \(
@@ -61,39 +66,61 @@
               )
            }x;
 
-my (@key,$instr,$outstr,$extra,$cnt);
-while ($buf =~ /$re/g) {
-	$instr=$1;
-	$extra=$2;
-	@key = split /,\s*/, "$3";
-	$cnt = @key;
-	if ( $cnt < 2 ){
-		print "=($cnt)= $instr ==> FUNC ERROR (too few args ) === \n";
-	} else {
-		if ( $cnt == 2 ) {
-			$key[0] =~ s/\'//g;
-			$key[1] =~ s/\'//g;
-			$outstr=findtxt2($key[0],$key[1]);
-			print "=($cnt)= $instr ==> $outstr === \n";
-			$buf =~ s{\$\Q$instr\E}{$outstr}s;
+	my (@key,$instr,$outstr,$extra,$params,$thrdparam,$cnt);
+	while ($buf =~ /$re/g) {
+		$instr=$1;
+		$extra=$2;
+		$params=$3;
+		@key = split /,\s*/, "$params";
+		$cnt = @key;
+		if ( $cnt < 2 ){
+			if ($verbose > 5) {print "=($cnt)= $instr ==> FUNC ERROR (too few args ) === \n"};
 		} else {
-			if ( $cnt == 3 ) {
+			if ( $cnt == 2 ) {
 				$key[0] =~ s/\'//g;
 				$key[1] =~ s/\'//g;
-				$outstr=findtxt3($key[0],$key[1],$key[2]);
-				print "=($cnt)= $instr ==> $outstr === \n";
+				$outstr=findtxt2($key[0],$key[1]);
+				if ($verbose > 5) {print "=($cnt)= $instr ==> $outstr === \n"};
 				$buf =~ s{\$\Q$instr\E}{$outstr}s;
 			} else {
-				if ( $cnt > 3 ) {
-					print "=($cnt)= $instr ==> FUNC ERROR (too many args) === \n";
+				if ( $cnt == 3 ) {
+					$key[0] =~ s/\'//g;
+					$key[1] =~ s/\'//g;
+					$thrdparam = $params;
+					$thrdparam =~ s/.[^,]*,.[^,]*,//g;
+					$outstr=findtxt3($key[0],$key[1],$thrdparam);
+					if ($verbose > 5) {print "=($cnt)= $instr ==> $outstr === \n"};
+					if ($verbose > 10) {print "=(*)= thrdparam ==> $thrdparam === \n"};
+					$buf =~ s{\$\Q$instr\E}{$outstr}s;
+				} else {
+					if ( $cnt > 3 ) {
+						$key[0] =~ s/\'//g;
+						$key[1] =~ s/\'//g;
+						$thrdparam = $params;
+						$thrdparam =~ s/.[^,]*,.[^,]*,//g;
+						$outstr=findtxt3($key[0],$key[1],$thrdparam);
+						if ($verbose > 5) {print "=($cnt)= $instr ==> FUNC ERROR (too many args) === \n"};
+						if ($verbose > 10) {print "=(*)= outstr ==> $outstr === \n"};
+						if ($verbose > 10) {print "=(*)= extra ==> $extra === \n"};
+						if ($verbose > 10) {print "=(*)= params ==> $params === \n"};
+						if ($verbose > 10) {print "=(*)= thrdparam ==> $thrdparam === \n"};
+						$buf =~ s{\$\Q$instr\E}{$outstr}s;
+					}
 				}
 			}
 		}
 	}
+	if ($verbose > 10) {print "$buf\n"};
 }
 
-print "$buf\n";
+if ( ! -f "alltab.txt" ){
+	system("find . -name '*.tab' | grep -v '.svn' | grep en_US | xargs cat > alltab.txt");
+}
 
+%tab = readalltab();
+if ($verbose > 1) {print "Reading $ARGV[0]\n"};
+tab2gettextfile($ARGV[0]);
+
 #$buf =~ /$re/;
 #print "\$1 = $1\n", "\$2 = $2\n";
 #my @key = split /,\s*/, "$2";




More information about the Fusionforge-commits mailing list