[Po4a-commits] "po4a/lib/Locale/Po4a Man.pm,1.102,1.103"

Nicolas FRANCOIS nekral-guest at alioth.debian.org
Fri Sep 2 20:05:56 UTC 2005


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

Modified Files:
	Man.pm 
Log Message:
The verbatim_groff_code and translate_groff_code options, wich permit to
support .de, .ie and .if sections.
With their documentation!


Index: Man.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Man.pm,v
retrieving revision 1.102
retrieving revision 1.103
diff -u -d -r1.102 -r1.103
--- Man.pm	2 Sep 2005 19:19:45 -0000	1.102
+++ Man.pm	2 Sep 2005 20:05:52 -0000	1.103
@@ -118,6 +118,18 @@
 
 Increase verbosity.
 
+=item B<verbatim_groff_code>
+
+With this option, the .de, .ie or .if sections are copied as is from the
+original to the translated document.
+
+=item B<translate_groff_code>
+
+With this option, the .de, .ie or .if sections will be proposed for the
+translation. You should only use this option if a translatable string is
+contained in one of these section. Otherwise, B<verbatim_groff_code>
+should be preferred.
+
 =back
 
 =head1 AUTHORING MAN PAGES COMPLIANT WITH PO4A::MAN
@@ -312,12 +324,17 @@
 
 
 ######## CONFIG #########
+# These variables indicate if the associated options were activated.
+my $translate_groff_code;
+my $verbatim_groff_code;
 sub initialize {
     my $self = shift;
     my %options = @_;
 
     $self->{options}{'debug'}='';
     $self->{options}{'verbose'}='';
+    $self->{options}{'translate_groff_code'}='';
+    $self->{options}{'verbatim_groff_code'}='';
 
     # reset the debug options
     %debug = ();
@@ -336,6 +353,17 @@
             $debug{$_} = 1;
         }
     }
+
+    if (defined $options{'translate_groff_code'}) {
+        $translate_groff_code = 1;
+    } else {
+        $translate_groff_code = 0;
+    }
+    if (defined $options{'verbatim_groff_code'}) {
+        $verbatim_groff_code = 1;
+    } else {
+        $verbatim_groff_code = 0;
+    }
 }
 
 my @comments = ();
@@ -360,6 +388,12 @@
         return ($line,$ref);
     }
 
+    # Do as few treatments as possible with the .de, .ie and .if sections
+    if ($line =~ /^\.\s*(if|ie|de)/) {
+        chomp $line;
+        return ($line,$ref);
+    }
+
     # Handle some escapes
     #   * reduce the number of \ in macros
     if ($line =~ /^\\?[.']/) {
@@ -572,6 +606,11 @@
     print STDERR "pre_trans($str)="
 	if ($debug{'pretrans'});
 
+    # Do as few treatments as possible with the .de, .ie and .if sections
+    if (defined $self->{type} && $self->{type} =~ m/^(ie|if|de)$/) {
+        return $str;
+    }
+
     # Note: if you want to implement \c support, the gdb man page is your playground
     die wrap_ref_mod($ref, "po4a::man", dgettext("po4a","Escape sequence \\c encountered. This is not completely handled yet."))
 	if ($str =~ /\\c/);
@@ -625,6 +664,11 @@
 
     print STDERR "post_trans($str)="
 	if ($debug{'postrans'});
+    
+    # Do as few treatments as possible with the .de, .ie and .if sections
+    if (defined $self->{type} && $self->{type} =~ m/^(ie|if|de)$/) {
+        return $str;
+    }
 
     # Post formatting, so that groff see the strange chars
     $str =~ s|\\-|-|sg; # in case the translator added some of them manually
@@ -1434,7 +1478,35 @@
 $macro{'ad'}=\&untranslated;
 # .de macro Define or redefine macro until .. is encountered.
 $macro{'de'}=sub {
-    die wrap_mod("po4a::man", dgettext("po4a", "This page defines a new macro with '.de'. Since po4a is not a real groff parser, this is not supported."));
+    if ($verbatim_groff_code or $translate_groff_code) {
+        my $self = shift;
+        my $paragraph = "@_";
+        my $end = ".";
+        if ($paragraph=~/^[.'][\t ]*de[\t ]+([^\t ]+)[\t ]+([^\t ]+)[\t ]$/) {
+            $end = $2;
+        }
+        my ($line, $ref) = $self->SUPER::shiftline();
+        chomp $line;
+        $paragraph .= "\n".$line;
+        while (defined($line) and $line ne ".$end") {
+            ($line, $ref) = $self->SUPER::shiftline();
+            if (defined $line) {
+                chomp $line;
+                $paragraph .= "\n".$line;
+            }
+        }
+        $paragraph .= "\n";
+        if ($verbatim_groff_code) {
+            $self->pushline($paragraph);
+        } else {
+            $self->pushline( $self->translate($paragraph,
+                                              $self->{ref},
+                                              "groff code",
+                                              "wrap" => 0) );
+        }
+    } else {
+        die wrap_mod("po4a::man", dgettext("po4a", "This page defines a new macro with '.de'. Since po4a is not a real groff parser, this is not supported."));
+    }
 };
 # .ds stringvar anything
 #                 Set stringvar to anything.
@@ -1472,8 +1544,53 @@
 # .ie cond anything  If cond then anything else goto .el.
 # .if cond anything  If cond then anything; otherwise do nothing.
 $macro{'ie'}=$macro{'if'}=sub {
-    die wrap_mod("po4a::man", dgettext("po4a",
-    	"This page uses conditionals with '%s'. Since po4a is not a real groff parser, this is not supported."), $_[1]);
+    if ($verbatim_groff_code or $translate_groff_code) {
+        my $self = shift;
+        my $m = $_[0];
+        my $paragraph = "@_";
+        my ($line,$ref);
+        my $count = 0;
+        $count = 1 if ($paragraph =~ m/(?<!\\)\\\{/s);
+        while (   ($paragraph =~ m/(?<!\\)\\$/s)
+               or ($count > 0)) {
+            ($line,$ref)=$self->SUPER::shiftline();
+            chomp $line;
+            $paragraph .= "\n".$line;
+            $count += 1 if ($line =~ m/(?<!\\)\\\{/s);
+            $count -= 1 if ($line =~ m/(?<!\\)\\\}/s);
+        }
+        if ($m eq '.ie') {
+            ($line,$ref)=$self->SUPER::shiftline();
+            chomp $line;
+            if ($line !~ m/^\.[ \t]*el\s/) {
+                die ".ie without .el\n"
+            }
+            my $paragraph2 = $line;
+            $count = 0;
+            $count = 1 if ($line =~ m/(?<!\\)\\\{/s);
+            while (   ($paragraph2 =~ m/(?<!\\)\\$/s)
+                   or ($count > 0)) {
+                ($line,$ref)=$self->SUPER::shiftline();
+                chomp $line;
+                $paragraph2 .= "\n".$line;
+                $count += 1 if ($line =~ m/(?<!\\)\\\{/s);
+                $count -= 1 if ($line =~ m/(?<!\\)\\\}/s);
+            }
+            $paragraph .= "\n".$paragraph2;
+        }
+        $paragraph .= "\n";
+        if ($verbatim_groff_code) {
+            $self->pushline($paragraph);
+        } else {
+            $self->pushline( $self->translate($paragraph,
+                                              $self->{ref},
+                                              "groff code",
+                                              "wrap" => 0) );
+        }
+    } else {
+        die wrap_mod("po4a::man", dgettext("po4a",
+            "This page uses conditionals with '%s'. Since po4a is not a real groff parser, this is not supported."), $_[1]);
+    }
 };
 # .in  N    Change indent according to N (default scaling indicator m).
 $macro{'in'}=\&untranslated;




More information about the Po4a-commits mailing list