[Po4a-commits] "po4a/lib/Locale/Po4a Text.pm, 1.6,
1.7 TransTractor.pm, 1.80, 1.81"
Nicolas FRANCOIS
nekral-guest at alioth.debian.org
Mon Oct 9 19:32:10 UTC 2006
Update of /cvsroot/po4a/po4a/lib/Locale/Po4a
In directory haydn:/tmp/cvs-serv19014/lib/Locale/Po4a
Modified Files:
Text.pm TransTractor.pm
Log Message:
* lib/Locale/Po4a/TransTractor.pm (translate): When the wrapcol
argument is negative, add the default wrapcol value. NOTE: It
does not take into account the argument of the po4a-translate's
--width option.
* lib/Locale/Po4a/Text.pm: Support for bulleted paragraphs:
extract the bullet's text, and wrap/reindent after translation.
A -o nobullets option was added to revert this behavior.
(this needs the TransTractor change)
Index: Text.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Text.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- Text.pm 9 Oct 2006 19:20:14 -0000 1.6
+++ Text.pm 9 Oct 2006 19:32:08 -0000 1.7
@@ -63,7 +63,17 @@
use Locale::Po4a::TransTractor;
use Locale::Po4a::Common;
-sub initialize {}
+my $bullets = 1;
+sub initialize {
+ my $self = shift;
+ my %options = @_;
+
+ $self->{options}{'nobullets'}='';
+
+ if (defined $options{'nobullets'}) {
+ $bullets = 0;
+ }
+}
sub parse {
my $self = shift;
@@ -114,6 +124,42 @@
sub do_paragraph {
my ($self, $paragraph, $wrap) = (shift, shift, shift);
return if ($paragraph eq "");
+
+ if ($bullets) {
+ # Detect bullets
+ # | * blah blah
+ # |<spaces> blah
+ # | ^-- aligned
+ # <empty line>
+ #
+ # Other bullets supported:
+ # - blah o blah + blah
+ # 1. blah 1) blah (1) blah
+ if ($paragraph =~ m/^(\s*)((?:[-*o+]|([0-9]+[.\)])|\([0-9]+\))\s+)([^\n]*\n)(.*)$/s) {
+ my $para = $5;
+ my $bullet = $2;
+ my $indent1 = $1;
+ my $indent2 = "$1".(' ' x length $bullet);
+ my $text = $4;
+ while ($para =~ s/^$indent2(\S[^\n]*\n)//s) {
+ $text .= $1;
+ }
+ # TODO: detect if a line starts with the same bullet
+ if ($para eq '' and $text !~ m/\S[ \t][ \t][ \t]+\S/s) {
+ my $trans = $self->translate($text,
+ $self->{ref},
+ "Bullet: '$bullet'",
+ "wrap" => 1,
+ "wrapcol" => - (length $indent2));
+ $trans =~ s/^/$indent1$bullet/s;
+ $trans =~ s/\n(.)/\n$indent2$1/sg;
+ $self->pushline( $trans."\n" );
+ return;
+ }
+ }
+ }
+ # TODO: detect indented paragraphs
+
$self->pushline( $self->translate($paragraph,
$self->{ref},
"Plain text",
Index: TransTractor.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/TransTractor.pm,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -d -r1.80 -r1.81
--- TransTractor.pm 8 Oct 2006 13:55:48 -0000 1.80
+++ TransTractor.pm 9 Oct 2006 19:32:08 -0000 1.81
@@ -832,6 +832,10 @@
Encode::from_to($string, $in_charset, $self->{TT}{po_in}->get_charset);
}
+ if (defined $options{'wrapcol'} && $options{'wrapcol'} < 0) {
+# FIXME: should be the parameter given with --width
+ $options{'wrapcol'} = 76 + $options{'wrapcol'};
+ }
my $transstring = $self->{TT}{po_in}->gettext($string,
'wrap' => $options{'wrap'}||0,
'wrapcol' => $options{'wrapcol'});
More information about the Po4a-commits
mailing list