[Po4a-commits] po4a/lib/Locale/Po4a Man.pm,1.80,1.81
Nicolas FRAN??OIS
po4a-devel@lists.alioth.debian.org
Sun, 03 Apr 2005 14:19:34 +0000
Update of /cvsroot/po4a/po4a/lib/Locale/Po4a
In directory haydn:/tmp/cvs-serv18411/lib/Locale/Po4a
Modified Files:
Man.pm
Log Message:
Remove comments from all lines, and display the comments in the PO.
This follow the proposal from Martin:
http://lists.alioth.debian.org/pipermail/po4a-devel/2005-April/000871.html
Index: Man.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Man.pm,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -d -r1.80 -r1.81
--- Man.pm 27 Feb 2005 22:53:52 -0000 1.80
+++ Man.pm 3 Apr 2005 14:19:32 -0000 1.81
@@ -327,6 +327,8 @@
}
}
+my @comments = ();
+my @next_comments = ();
# This function returns the next line of the document being parsed
# (and its reference).
# It overload the Transtractor shiftline to handle:
@@ -339,6 +341,7 @@
sub shiftline {
my $self = shift;
# call Transtractor's shiftline
+NEW_LINE:
my ($line,$ref) = $self->SUPER::shiftline();
if (!defined $line) {
@@ -360,6 +363,61 @@
$line =~ s/\\\././g;
chomp $line;
+ if ($line =~ m/^(.*?)(?:(?<!\\)\\"(.*))$/) {
+ my ($l, $c) = ($1, $2);
+ $line = $l;
+ # Check for comments indicating that the file was generated.
+ if ($c =~ /Pod::Man/) {
+ warn wrap_mod("po4a::man", dgettext("po4a", "This file was generated with Pod::Man. Translate the pod file with the pod module of po4a."));
+ exit 254;
+ } elsif ($c =~ /generated by help2man/) {
+ warn wrap_mod("po4a::man", dgettext("po4a", "This file was generated with help2man. Translate the source file with the regular gettext."));
+ } elsif ($c =~ /with docbook-to-man/) {
+ warn wrap_mod("po4a::man", dgettext("po4a", "This file was generated with docbook-to-man. Translate the source file with the sgml module of po4a."));
+ exit 254;
+ } elsif ($c =~ /generated by docbook2man/) {
+ warn wrap_mod("po4a::man", dgettext("po4a", "This file was generated with docbook2man. Translate the source file with the sgml module of po4a."));
+ exit 254;
+ } elsif ($c =~ /created with latex2man/) {
+ warn wrap_mod("po4a::man", dgettext("po4a",
+ "This file was generated with %s. ".
+ "You should translate the source file, but continuing anyway."
+ ),"latex2man");
+ } elsif ($c =~ /Generated by db2man.xsl/) {
+ warn wrap_mod("po4a::man", dgettext("po4a","This file was generated with db2man.xsl. Translate the source file with the xml module of po4a."));
+ exit 254;
+ } elsif ($c =~ /generated automatically by mtex2man/) {
+ warn wrap_mod("po4a::man", dgettext("po4a",
+ "This file was generated with %s. ".
+ "You should translate the source file, but continuing anyway."
+ ),"mtex2man");
+ } elsif ($c =~ /THIS FILE HAS BEEN AUTOMATICALLY GENERATED. DO NOT EDIT./ ||
+ $c =~ /DO NOT EDIT/i || $c =~ /generated/i) {
+ warn wrap_mod("po4a::man", dgettext("po4a",
+ "This file contains the line '%s'. ".
+ "You should translate the source file, but continuing anyway."
+ ),$l."\\\"".$c);
+ }
+
+ if ($line =~ m/^[.']*$/) {
+ if ($c !~ m/^\s*$/) {
+ # This commentted line may be comment for the next paragraph
+ push @next_comments, $c;
+ }
+ if ($line =~ m/^[.']+$/) {
+ # those lines are ignored
+ # (empty lines are a little bit different)
+ goto NEW_LINE;
+ }
+ } else {
+ push @comments, $c;
+ }
+ } else {
+ # finally, we did not reach the end of the paragraph. The comments
+ # belong to the current paragraph.
+ push @comments, @next_comments;
+ @next_comments = ();
+ }
while ($line =~ /\\$/ || $line =~ /^(\.[BI])\s*$/) {
my ($l2,$r2)=$self->SUPER::shiftline();
chomp($l2);
@@ -410,6 +468,23 @@
return ($line,$ref);
}
+# Overload Transtractor's pushline.
+# This pushline first push comments (if there are comments for the
+# current line, and the line is not empty), and then push the line.
+sub pushline {
+ my ($self, $line) = (shift, shift);
+ if ($line !~ m/^\s*$/) {
+ # add comments
+ foreach my $c (@comments) {
+ # comments are pushed (maybe at the wrong place).
+ $self->SUPER::pushline(".\\\"$c\n");
+ }
+ @comments = ();
+ }
+
+ $self->SUPER::pushline($line);
+}
+
# The default unshiftline from Transtractor may fail because shiftline
# is overloaded
sub unshiftline {
@@ -607,6 +682,7 @@
return $str if ($str eq "\n");
$str=pre_trans($self,$str,$ref||$self->{ref},$type);
+ $options{'comment'} .= join('\n', @comments);
# Translate this
$str = $self->SUPER::translate($str,
$ref||$self->{ref},
@@ -693,43 +769,6 @@
}
# Special case: Don't change these lines
- # Check for comments indicating that the file was generated.
- if ($macro eq '\"' ||
- $macro eq '"') {
- if ($line =~ /Pod::Man/) {
- warn wrap_mod("po4a::man", dgettext("po4a", "This file was generated with Pod::Man. Translate the pod file with the pod module of po4a."));
- exit 254;
- } elsif ($line =~ /generated by help2man/) {
- warn wrap_mod("po4a::man", dgettext("po4a", "This file was generated with help2man. Translate the source file with the regular gettext."));
- } elsif ($line =~ /with docbook-to-man/) {
- warn wrap_mod("po4a::man", dgettext("po4a", "This file was generated with docbook-to-man. Translate the source file with the sgml module of po4a."));
- exit 254;
- } elsif ($line =~ /generated by docbook2man/) {
- warn wrap_mod("po4a::man", dgettext("po4a", "This file was generated with docbook2man. Translate the source file with the sgml module of po4a."));
- exit 254;
- } elsif ($line =~ /created with latex2man/) {
- warn wrap_mod("po4a::man", dgettext("po4a",
- "This file was generated with %s. ".
- "You should translate the source file, but continuing anyway."
- ),"latex2man");
- } elsif ($line =~ /Generated by db2man.xsl/) {
- warn wrap_mod("po4a::man", dgettext("po4a","This file was generated with db2man.xsl. Translate the source file with the xml module of po4a."));
- exit 254;
- } elsif ($line =~ /generated automatically by mtex2man/) {
- warn wrap_mod("po4a::man", dgettext("po4a",
- "This file was generated with %s. ".
- "You should translate the source file, but continuing anyway."
- ),"mtex2man");
- } elsif ($line =~ /THIS FILE HAS BEEN AUTOMATICALLY GENERATED. DO NOT EDIT./ ||
- $line =~ /DO NOT EDIT/i || $line =~ /generated/i) {
- warn wrap_mod("po4a::man", dgettext("po4a",
- "This file contains the line '%s'. ".
- "You should translate the source file, but continuing anyway."
- ),$line);
- }
- }
-
- # Special case: Don't change these lines
# .\" => comments
# ." => comments
# . => empty point on the line
@@ -810,6 +849,11 @@
$self->pushline($line."\n");
}
+ # finally, we did not reach the end of the paragraph. The comments
+ # belong to the current paragraph.
+ push @comments, @next_comments;
+ @next_comments = ();
+
# Reinit the loop
($line,$ref)=$self->shiftline();
undef $self->{type};
@@ -819,6 +863,12 @@
do_paragraph($self,$paragraph,$wrapped_mode);
$wrapped_mode = $wrapped_mode eq 'NO' ? 'YES' : $wrapped_mode;
$paragraph="";
+ }
+
+ # flush the last comments
+ push @comments, @next_comments;
+ for my $c (@comments) {
+ $self->pushline(".\\\"$c\n");
}
} # end of main