[Po4a-devel][CVS] po4a po4a,1.8,1.9

Martin Quinson po4a-devel@lists.alioth.debian.org
Sun, 18 Jul 2004 08:33:38 +0000


Update of /cvsroot/po4a/po4a
In directory haydn:/tmp/cvs-serv31654

Modified Files:
	po4a 
Log Message:
several -v=> more verbosity; let the addendum work; various bug fix and cleanup; invert the loop on document and lang, so that all doc of the same lang are together

Index: po4a
===================================================================
RCS file: /cvsroot/po4a/po4a/po4a,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- po4a	18 Jul 2004 07:15:16 -0000	1.8
+++ po4a	18 Jul 2004 08:33:36 -0000	1.9
@@ -178,14 +178,14 @@
     exit 0;
 }
 
-my ($help,$type,$debug,$verbose,$quiet,@options);
-$verbose = 0;
+my ($help,$type,$debug,@verbose,$quiet,@options);
+@verbose = ();
 $debug = 0;
 my ($threshold)=(80);
 Getopt::Long::config('bundling', 'no_getopt_compat', 'no_auto_abbrev');
 GetOptions(
         'help|h'        => \$help,
-        'verbose|v'     => \$verbose,
+        'verbose|v'     => \@verbose,
         'debug|d'       => \$debug,
         'quiet|q'       => \$quiet,
 	'keep|k=s'      => \$threshold,
@@ -195,6 +195,7 @@
 # Argument check
 $help && pod2usage (0);
 
+my ($verbose) = (scalar @verbose);
 $verbose = 1 if $debug;
 $verbose = -1 if $quiet;
 my %options = (
@@ -223,12 +224,13 @@
     $nb++;
     s/#.*//; 
     $line.=$_;
-    chomp($line);
-    next if ($line =~ s/\\$//);
-    next unless ($line =~ /\S/);
+    $line =~ s/\t/ /g;
     $line =~ s/ +/ /g;
     $line =~ s/^ //;
     $line =~ s/ $//;
+    chomp($line);
+    next if ($line =~ s/\\$//);
+    next unless ($line =~ /\S/);
     
     die sprintf("%s:%d: ".gettext("Syntax error: %s")."\n",$config_file,$nb,$line)
       unless ($line =~ m/^\[([^\]]*)\] (\S+) (.*)$/ || $line =~ m/^\[([^\]]*)\] (\S+)$/);
@@ -250,7 +252,7 @@
 	$pot_filename = $main;
 	foreach my $arg (split(/ /,$args)) {
 	    die sprintf("%s:%d: ".
-		        gettext("Unparsable argument '%s'").
+		        gettext("Unparsable argument '%s'.").
 		        "\n",
 	                $config_file,$nb,$arg)
 	      unless ($arg =~ /^([^:]*):(.*)/);
@@ -261,20 +263,30 @@
 	$document{$main}{'format'} = $1;	
 	foreach my $arg (split(/ /,$args)) {
 	    die sprintf("%s:%d: ".
-		        gettext("Unparsable argument '%s'").
+		        gettext("Unparsable argument '%s' (%s).").
 		        "\n",
-	                $config_file,$nb,$arg)
+	                $config_file,$nb,$arg,$line)
 	      unless ($arg =~ /^([^:]*):(.*)/);
+	    my ($lang,$trans)=($1,$2);
 	    die sprintf("%s:%d: ".
 		        gettext("The translated and master file are the same."),
 		        $config_file,$nb)
-	      if ($main eq $2);
-	    $document{$main}{$1} = $2;
+	      if ($main eq $trans);
+	    
+	    if ($lang =~ /add_/) {
+		push @{$document{$main}{$lang}},$trans;
+	    } else {
+		die sprintf("%s:%d: ".
+		            gettext("Translation of %s in %s redefined"),
+		            $config_file,$nb,$main,$lang)
+		  if (defined $document{$main}{$lang});
+		$document{$main}{$lang} = $trans;
+	    }
 	}
 
     } else {
 	die sprintf("%s:%d: ".
-	            gettext("Unparsable command '%s'")."\n",
+	            gettext("Unparsable command '%s'.")."\n",
 	            $config_file,$nb,$cmd);
     }
   
@@ -311,8 +323,8 @@
     if (-e $po_filename{$lang}) {
 	print STDERR sprintf(gettext("Updating %s: "),$po_filename{$lang})
 	    if $verbose;    
-	system ("msgmerge","-U",$po_filename{$lang},$pot_filename) == 0 ||
-	    die sprintf(gettext("Error while running msgmerge: %s"),$!)."\n";
+	system ("msgmerge -U ".$po_filename{$lang}." $pot_filename ".($verbose?"":">/dev/null 2>/dev/null"))
+	  && die sprintf(gettext("Error while running msgmerge: %s"),$!)."\n";
 	system "msgfmt --statistics -v -o /dev/null ".$po_filename{$lang} 
 	  if $verbose;
     } else {
@@ -324,9 +336,10 @@
 }
 
 # update all translations
-foreach my $master (keys %document) {
-    LANG: foreach $lang (keys %{$document{$master}}) {
-	next if $lang eq "format" || $lang =~ /^add_/;
+
+foreach $lang (sort keys %po_filename) {
+    DOC: foreach my $master (keys %document) {
+	next unless defined $document{$master}{$lang};
 	
 	my $doc=Locale::Po4a::Chooser::new($document{$master}{'format'} ,%options);
 	
@@ -341,19 +354,19 @@
 	my ($percent,$hit,$queries) = $doc->stats();
 	
 	if ($percent<$threshold)  {
-	    print STDERR sprintf(gettext("Discard the translation %s (only %s%% translated; need %s%%)."),
+	    print STDERR sprintf(gettext("Discard %s (only %s%% translated; need %s%%)."),
 		                 $document{$master}{$lang},$percent,$threshold)."\n";
 	    unlink($document{$master}{$lang}) if (-e $document{$master}{$lang});
-	    next LANG;
+	    next DOC;
 	}
     
 	if (defined ($document{$master}{"add_$lang"})) {
-	    foreach my $add ($document{$master}{"add_$lang"}) {
-		if ( !$doc->addendum($_) ) {
+	    foreach my $add (@{$document{$master}{"add_$lang"}}) {
+		if ( !$doc->addendum($add) ) {
 		    die sprintf(gettext("Addendum %s does apply to %s (translation discarded)."),
 			$add,$document{$master}{$lang})."\n";
 		    unlink($document{$master}{$lang}) if (-e $document{$master}{$lang});
-		    next LANG;
+		    next DOC;
 		}
 	    }
 	}