[Po4a-commits] r2608 - /trunk/lib/Locale/Po4a/Text.pm

barbier at users.alioth.debian.org barbier at users.alioth.debian.org
Wed Oct 3 22:42:38 UTC 2012


Author: barbier
Date: Wed Oct  3 22:42:38 2012
New Revision: 2608

URL: http://svn.debian.org/wsvn/po4a/?sc=1&rev=2608
Log:
AsciiDoc: add support for automatic comments

AsciiDoc has two kinds of comments:
 1. line comments, which consists of "//"
 2. line block, enclosed by lines of slashes (at least 4 slashes)

Those comments will be extracted and written into PO files; they may
be useful to give hints to translators.

There is one caveat though, it is not always clear to know if comments
must be written before or after the text.
Normally comments are written just before text.  But this is different
with lists.  For instance consider a list like:

  // Comment 1
  - Note 1.
  // Comment 2
  - Note 2.
  // Comment 3

Running AsciiDoc parser with 'showcomments' attribute shows that comment 2
belongs to the first item, and comment 3 to the second item.
So here po4a will put comments 1 and 2 into the first item, and comment 3
into the second one.

Since comment location is quite hard to parse correctly, they are not
written into translated files in order to avoid confusion.

Modified:
    trunk/lib/Locale/Po4a/Text.pm

Modified: trunk/lib/Locale/Po4a/Text.pm
URL: http://svn.debian.org/wsvn/po4a/trunk/lib/Locale/Po4a/Text.pm?rev=2608&op=diff
==============================================================================
--- trunk/lib/Locale/Po4a/Text.pm (original)
+++ trunk/lib/Locale/Po4a/Text.pm Wed Oct  3 22:42:38 2012
@@ -152,6 +152,8 @@
 
 my $parse_func = \&parse_fallback;
 
+my @comments = ();
+
 =back
 
 =cut
@@ -396,13 +398,22 @@
 
 sub parse_asciidoc {
     my ($self,$line,$ref,$paragraph,$wrapped_mode,$expect_header,$end_of_paragraph) = @_;
-    if ((defined $self->{verbatim}) and ($self->{verbatim} == 2)) {
+    if ((defined $self->{verbatim}) and ($self->{verbatim} == 3)) {
         # Untranslated blocks
         $self->pushline($line."\n");
-        if ($line =~ m/^(\/{4,}|~{4,})$/) {
+        if ($line =~ m/^~{4,}$/) {
             undef $self->{verbatim};
             undef $self->{type};
             $wrapped_mode = 1;
+        }
+    } elsif ((defined $self->{verbatim}) and ($self->{verbatim} == 2)) {
+        # CommentBlock
+        if ($line =~ m/^\/{4,}$/) {
+            undef $self->{verbatim};
+            undef $self->{type};
+            $wrapped_mode = 1;
+        } else {
+            push @comments, $line;
         }
     } elsif ((not defined($self->{verbatim})) and ($line =~ m/^(\+|--)$/)) {
         # List Item Continuation or List Block
@@ -422,9 +433,11 @@
         my $t = $self->translate($paragraph,
                                  $self->{ref},
                                  "Title $level",
+                                 "comment" => join("\n", @comments),
                                  "wrap" => 0);
         $self->pushline($t."\n");
         $paragraph="";
+        @comments=();
         $wrapped_mode = 1;
         $self->pushline(($level x (columns($t, $self->{TT}{po_in}{encoder}, $ref)))."\n");
     } elsif ($line =~ m/^(={1,5})( +)(.*?)( +\1)?$/) {
@@ -439,8 +452,10 @@
         my $t = $self->translate($title,
                                  $self->{ref},
                                  "Title $titlelevel1",
+                                 "comment" => join("\n", @comments),
                                  "wrap" => 0);
         $self->pushline($titlelevel1.$titlespaces.$t.$titlelevel2."\n");
+        @comments=();
         $wrapped_mode = 1;
     } elsif ($line =~ m/^(\/{4,}|\+{4,}|-{4,}|\.{4,}|\*{4,}|_{4,}|={4,}|~{4,}|\|={4,})$/) {
         # Found one delimited block
@@ -490,13 +505,16 @@
                 } elsif ($t eq "~") {
                     # Filter blocks, TBC: not translated
                     $wrapped_mode = 0;
-                    $self->{verbatim} = 2;
+                    $self->{verbatim} = 3;
                 }
                 $self->{type} = $type;
             }
             $paragraph="";
-            $self->pushline($line."\n");
-        }
+            $self->pushline($line."\n") unless defined($self->{verbatim}) && $self->{verbatim} == 2;
+        }
+    } elsif ((not defined($self->{verbatim})) and ($line =~ m/^\/\/(.*)/)) {
+        # Comment line
+        push @comments, $1;
     } elsif (not defined $self->{verbatim} and
              ($line =~ m/^\[\[([^\]]*)\]\]$/)) {
         # Found BlockId
@@ -539,8 +557,10 @@
         my $t = $self->translate($arg,
                                  $self->{ref},
                                  "$type",
+                                 "comment" => join("\n", @comments),
                                  "wrap" => 0);
         $self->pushline("[$quote$type$quote, $t]\n");
+        @comments=();
         $wrapped_mode = 1;
         if ($type  eq "verse") {
             $wrapped_mode = 0;
@@ -556,8 +576,10 @@
         my $t = $self->translate($arg,
                                  $self->{ref},
                                  "icon",
+                                 "comment" => join("\n", @comments),
                                  "wrap" => 0);
         $self->pushline("[icon=\"$t\"]\n");
+        @comments=();
         $wrapped_mode = 1;
         undef $self->{bullet};
         undef $self->{indent};
@@ -569,8 +591,10 @@
         my $t = $self->translate($arg,
                                  $self->{ref},
                                  "caption",
+                                 "comment" => join("\n", @comments),
                                  "wrap" => 0);
         $self->pushline("[icons=None, caption=\"$t\"]\n");
+        @comments=();
         $wrapped_mode = 1;
         undef $self->{bullet};
         undef $self->{indent};
@@ -588,8 +612,10 @@
         my $t = $self->translate($label,
                                  $self->{ref},
                                  "Labeled list",
+                                 "comment" => join("\n", @comments),
                                  "wrap" => 0);
         $self->pushline("$indent$t$labelend\n");
+        @comments=();
     } elsif (not defined $self->{verbatim} and
              ($line =~ m/^(\s*)(\S.*)((?:::|;;)\s+)(.*)$/)) {
         my $indent = $1;
@@ -605,8 +631,10 @@
         my $t = $self->translate($label,
                                  $self->{ref},
                                  "Labeled list",
+                                 "comment" => join("\n", @comments),
                                  "wrap" => 0);
         $self->pushline("$indent$t$labelend");
+        @comments=();
     } elsif (not defined $self->{verbatim} and
              ($line =~ m/^\:(\S.*?)(:\s*)(.*)$/)) {
         my $attrname = $1;
@@ -621,8 +649,10 @@
         my $t = $self->translate($attrvalue,
                                  $self->{ref},
                                  "Attribute :$attrname:",
+                                 "comment" => join("\n", @comments),
                                  "wrap" => 0);
         $self->pushline(":$attrname$attrsep$t\n");
+        @comments=();
     } elsif (not defined $self->{verbatim} and
              ($line !~ m/^\.\./) and ($line =~ m/^\.(\S.*)$/)) {
         my $title = $1;
@@ -635,8 +665,10 @@
         my $t = $self->translate($title,
                                  $self->{ref},
                                  "Block title",
+                                 "comment" => join("\n", @comments),
                                  "wrap" => 0);
         $self->pushline(".$t\n");
+        @comments=();
     } elsif (not defined $self->{verbatim} and
              ($line =~ m/^(\s*)((?:[-*o+]|(?:[0-9]+[.\)])|(?:[a-z][.\)])|\([0-9]+\)|\.|\.\.)\s+)(.*)$/)) {
         my $indent = $1||"";
@@ -866,7 +898,9 @@
     my $t = $self->translate($paragraph,
                              $self->{ref},
                              $type,
+                             "comment" => join("\n", @comments),
                              "wrap" => $wrap);
+    @comments = ();
     if (defined $self->{bullet}) {
         my $bullet = $self->{bullet};
         my $indent1 = $self->{indent};




More information about the Po4a-commits mailing list