[Po4a-devel][CVS] po4a/lib/Locale/Po4a TransTractor.pm,1.24,1.25

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


Update of /cvsroot/po4a/po4a/lib/Locale/Po4a
In directory haydn:/tmp/cvs-serv31704/lib/Locale/Po4a

Modified Files:
	TransTractor.pm 
Log Message:
Addendum: More robust to user error; message polishing

Index: TransTractor.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/TransTractor.pm,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- TransTractor.pm	18 Jul 2004 06:10:24 -0000	1.24
+++ TransTractor.pm	18 Jul 2004 08:35:05 -0000	1.25
@@ -533,9 +533,11 @@
     
     unless ($filename) {
 	warn(dgettext("po4a",
-	    "Can't insert addendum when not given the filename")."\n");
+	    "Can't apply addendum when not given the filename")."\n");
 	return 0;
     }
+    die sprintf(dgettext("po4a","Addendum %s does not exist.")."\n",$filename)
+      unless -e $filename;
   
     my ($errcode,$mode,$position,$boundary,$bmode,$lang,$content)=
 	addendum_parse($filename);
@@ -556,8 +558,8 @@
     }
 
     if ($mode eq "before") {
-	if ($self->verbose() > 0) {
-	    map { print STDERR sprintf(dgettext("po4a","Adding the addendum %s before the line:\n%s"),
+	if ($self->verbose() > 1) {
+	    map { print STDERR sprintf(dgettext("po4a","Addendum '%s' applied before this line: %s"),
 			 $filename,$_)."\n" if (/$position/);
  	        } @{$self->{TT}{doc_out}};
 	}
@@ -567,35 +569,34 @@
 	my @newres=();
 	while (my $line=shift @{$self->{TT}{doc_out}}) {
 	    push @newres,$line;
+	    my $outline=mychomp($line);
+	    $outline =~ s/^[ \t]*//;
+	      
 	    if ($line =~ m/$position/) {
-		print STDERR sprintf(dgettext("po4a",
-			"Adding the addendum %s after the section begining with the line:\n%s"),
-			       $filename,mychomp($line))."\n" if ($self->verbose() > 0);
 		while ($line=shift @{$self->{TT}{doc_out}}) {
 		    last if ($line=~/$boundary/);
 		    push @newres,$line;
 		}
 		if (defined $line) {
 		    if ($bmode eq 'before') {
-			printf STDERR (dgettext("po4a",
-				"Next section begins with:\n".
-				"%s\n".
-				"Addendum added before this line."),
-				       mychomp($line))."\n" if ($self->verbose() > 0);
+			print sprintf (dgettext("po4a",
+			    "Addendum '%s' applied before this line: %s")."\n",
+			    $filename,$outline)
+			  if ($self->verbose() > 1);
 			push @newres,$content;
 			push @newres,$line;
 		    } else {
-			printf STDERR (dgettext("po4a",
-				"This section ends with:\n".
-				"%s\n".
-				"Addendum added after this line."),
-				       mychomp($line))."\n" if ($self->verbose() > 0);
+			print sprintf (dgettext("po4a",
+			    "Addendum '%s' applied after the line: %s.")."\n",
+			    $filename,$outline)
+			  if ($self->verbose() > 1);
 			push @newres,$line;
 			push @newres,$content;
 		    }
 		} else {
-		    printf STDERR (dgettext("po4a","Can't find the end of the section in the file. Addendum added at the end of the file."))."\n"
-			   if ($self->verbose() > 0);
+		    print sprintf (dgettext("po4a","Addendum '%s' applied at the end of the file.")."\n",
+		        $filename)
+		      if ($self->verbose() > 1);
 		    push @newres,$content;
 		}
 	    }