[Po4a-commits] "po4a/lib/Locale/Po4a Texinfo.pm,1.7,1.8"

Nicolas FRANCOIS nekral-guest at alioth.debian.org
Sun Sep 16 14:17:53 UTC 2007


Update of /cvsroot/po4a/po4a/lib/Locale/Po4a
In directory alioth:/tmp/cvs-serv24803/lib/Locale/Po4a

Modified Files:
	Texinfo.pm 
Log Message:
 * Define specific translate_buffer functions for the menu (menu,
   direntry, detailmenu) and ignore environments.
 * detailmenu is no more verbatim.
 * menu, detailmenu and direntry do not need an env_separators definition
   anymore.


Index: Texinfo.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Texinfo.pm,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- Texinfo.pm	16 Sep 2007 13:53:05 -0000	1.7
+++ Texinfo.pm	16 Sep 2007 14:17:51 -0000	1.8
@@ -97,6 +97,7 @@
             %commands             %environments
             %command_categories   %separated
             %env_separators       %debug
+            %translate_buffer_env
             @exclude_include      @comments);
 *RE_ESCAPE             = \$Locale::Po4a::TeX::RE_ESCAPE;
 *ESCAPE                = \$Locale::Po4a::TeX::ESCAPE;
@@ -111,6 +112,7 @@
 *separated             = \%Locale::Po4a::TeX::separated;
 *env_separators        = \%Locale::Po4a::TeX::env_separators;
 *debug                 = \%Locale::Po4a::TeX::debug;
+*translate_buffer_env  = \%Locale::Po4a::TeX::translate_buffer_env;
 *exclude_include       = \@Locale::Po4a::TeX::exclude_include;
 *comments              = \@Locale::Po4a::TeX::comments;
 
@@ -275,6 +277,76 @@
     return ($translated,@$env);
 }
 
+sub translate_buffer_menu {
+    my ($self,$buffer, at env) = (shift,shift, at _);
+    print STDERR "translate_buffer_menu($buffer, at env)="
+        if ($debug{'translate_buffer'});
+    my $translated_buffer = "";
+    my $spaces = "";
+    if ($buffer =~ m/(\s*)$/s) {
+        $spaces = $1;
+    }
+
+
+    while ($buffer =~ m/^(.*?)((?:\n|^)\* )(.*)$/s) {
+        my $sep = $2;
+        $buffer = $3;
+        my($t, @e) = $self->translate_buffer_menuentry($1, @env, "menuentry");
+        $translated_buffer .= $t.$sep;
+    }
+    my($t, @e) = $self->translate_buffer_menuentry($buffer, @env, "menuentry");
+    $translated_buffer .= $t;
+
+    $translated_buffer .= $spaces;
+
+    print STDERR "($translated_buffer, at env)\n"
+        if ($debug{'translate_buffer'});
+    return ($translated_buffer, at env);
+}
+$translate_buffer_env{"menu"}       = \&translate_buffer_menu;
+$translate_buffer_env{"detailmenu"} = \&translate_buffer_menu;
+$translate_buffer_env{"direntry"}   = \&translate_buffer_menu;
+
+my $menu_width = 78;
+my $menu_sep_width = 30;
+sub translate_buffer_menuentry {
+    my ($self,$buffer, at env) = (shift,shift, at _);
+    print STDERR "translate_buffer_menuentry($buffer, at env)="
+        if ($debug{'translate_buffer'});
+
+    my $translated_buffer = "";
+    
+    if (   $buffer =~ m/^(.*?)(::)\s+(.*)$/s
+        or $buffer =~ m/^(.*?: .*?)(\.)\s+(.*)$/s) {
+        my ($name, $sep, $description) = ($1, $2, $3);
+        my ($t, @e) = $self->translate_buffer($name, @env);
+        $translated_buffer = $t.$sep."  ";
+        my $l = length($translated_buffer) + 2;
+        if ($l < $menu_sep_width-1) {
+            $translated_buffer .= ' 'x($menu_sep_width-1-$l);
+            $l = $menu_sep_width-1;
+        }
+        ($t, @e) = $self->translate_buffer($description, @env);
+        $t =~ s/\n//sg;
+        $t = Locale::Po4a::Po::wrap($t, $menu_width-$l-2);
+        my $spaces = ' 'x($l+2);
+        $t =~ s/\n/\n$spaces/sg;
+        $translated_buffer .= $t;
+    }
+
+    print STDERR "($translated_buffer, at env)\n"
+        if ($debug{'translate_buffer'});
+    return ($translated_buffer, at env);
+}
+
+sub translate_buffer_ignore {
+    my ($self,$buffer, at env) = (shift,shift, at _);
+    print STDERR "translate_buffer_ignore($buffer, at env);\n"
+        if ($debug{'translate_buffer'});
+    return ($buffer, at env);
+}
+$translate_buffer_env{"ignore"} = \&translate_buffer_ignore;
+
 foreach (qw(appendix section cindex findex kindex pindex vindex subsection
             dircategory subtitle include
             exdent center unnumberedsec
@@ -415,7 +487,6 @@
     $translate_line_command{$_} = 0;
     $break_line{$_} = 1;
 }
-register_verbatim_environment('detailmenu');
 foreach (qw(enumerate multitable ifset)) {
     $commands{$_} = \&environment_line_command;
     $break_line{$_} = 1;
@@ -426,8 +497,6 @@
     $break_line{$_} = 1;
 }
 
-# FIXME: maybe format and menu should just be verbatim environments.
-$env_separators{'direntry'} = $env_separators{'menu'} = $env_separators{'detailmenu'} = "(?:(?:^|\n)\\\*|::|\.  )";
 $env_separators{'format'} = "(?:(?:^|\n)\\\*|END-INFO-DIR-ENTRY|START-INFO-DIR-ENTRY)";
 $env_separators{'multitable'} = "(?:\@item|\@tab)";
 




More information about the Po4a-commits mailing list