summaryrefslogtreecommitdiff
path: root/perl/Locale/Po4a
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2010-07-19 17:20:27 +0200
committerJonas Smedegaard <dr@jones.dk>2010-07-19 17:20:27 +0200
commit5b9702f32e0d8df28bd7019443a2aea56132049f (patch)
tree6475f22f77f882e37f3c5d009ec00f0629b68868 /perl/Locale/Po4a
parent86b629053ff7f0dbf984aa2236b63dba0616957d (diff)
parent077f4b7319c36f2c8bc243b462a992f10e896573 (diff)
Merge branch 'master' into nonedit
Conflicts (manually resolved: merge old and new parts): .gitmodules
Diffstat (limited to 'perl/Locale/Po4a')
-rw-r--r--perl/Locale/Po4a/Text.pm121
1 files changed, 117 insertions, 4 deletions
diff --git a/perl/Locale/Po4a/Text.pm b/perl/Locale/Po4a/Text.pm
index d9fcc88..676363d 100644
--- a/perl/Locale/Po4a/Text.pm
+++ b/perl/Locale/Po4a/Text.pm
@@ -21,6 +21,8 @@
#
########################################################################
+=encoding UTF-8
+
=head1 NAME
Locale::Po4a::Text - Convert text documents from/to PO files
@@ -34,7 +36,7 @@ areas where they were not expected like documentation.
Locale::Po4a::Text is a module to help the translation of text documents into
other [human] languages.
-Paragraphs are splitted on empty lines (or lines containing only spaces or
+Paragraphs are split on empty lines (or lines containing only spaces or
tabulations).
If a paragraph contains a line starting by a space (or tabulation), this
@@ -62,7 +64,7 @@ These are this module's particular options:
=over
-=item B<nobullet>
+=item B<nobullets>
Deactivate detection of bullets.
@@ -74,6 +76,37 @@ rewrap this paragraph in the generated PO file and in the translation.
my $bullets = 1;
+=item B<tabs>=I<mode>
+
+Specify how tabulations shall be handled. The I<mode> can be any of:
+
+=over
+
+=item B<split>
+
+Lines with tabulations introduce breaks in the current paragraph.
+
+=item B<verbatim>
+
+Paragraph containing tabulations will not be re-wrapped.
+
+=back
+
+By default, tabulations are considered as spaces.
+
+=cut
+
+my $tabs = "";
+
+=item B<breaks>=I<regex>
+
+A regular expression matching lines which introduce breaks.
+The regular expression will be anchored so that the whole line must match.
+
+=cut
+
+my $breaks;
+
=item B<debianchangelog>
Handle the header and footer of
@@ -116,12 +149,35 @@ sub initialize {
my $self = shift;
my %options = @_;
- $self->{options}{'nobullets'}='';
+ $self->{options}{'asciidoc'} = 1;
+ $self->{options}{'breaks'} = 1;
+ $self->{options}{'debianchangelog'} = 1;
+ $self->{options}{'debug'} = 1;
+ $self->{options}{'fortunes'} = 1;
+ $self->{options}{'markdown'} = 1;
+ $self->{options}{'nobullets'} = 1;
+ $self->{options}{'tabs'} = 1;
+ $self->{options}{'verbose'} = 1;
+
+ foreach my $opt (keys %options) {
+ die wrap_mod("po4a::text",
+ dgettext("po4a", "Unknown option: %s"), $opt)
+ unless exists $self->{options}{$opt};
+ $self->{options}{$opt} = $options{$opt};
+ }
if (defined $options{'nobullets'}) {
$bullets = 0;
}
+ if (defined $options{'tabs'}) {
+ $tabs = $options{'tabs'};
+ }
+
+ if (defined $options{'breaks'}) {
+ $breaks = $options{'breaks'};
+ }
+
if (defined $options{'debianchangelog'}) {
$debianchangelog=1;
}
@@ -194,7 +250,9 @@ sub parse {
undef $self->{type};
$wrapped_mode = 1;
}
- } elsif ($line =~ /^\s*$/) {
+ } elsif ( ($line =~ /^\s*$/)
+ or ( defined $breaks
+ and $line =~ m/^$breaks$/)) {
# Break paragraphs on lines containing only spaces
do_paragraph($self,$paragraph,$wrapped_mode);
$paragraph="";
@@ -467,6 +525,50 @@ sub parse {
$self->{indent} = $indent;
$self->{bullet} = "";
}
+ } elsif ($markdown and
+ (not defined($self->{verbatim})) and
+ ($line =~ m/^(={4,}|-{4,})$/) and
+ (defined($paragraph) )and
+ ($paragraph =~ m/^[^\n]*\n$/s) and
+ (length($paragraph) == (length($line)+1))) {
+ # XXX: There can be any number of underlining according
+ # to the documentation. This detection, which avoid
+ # translating the formatting, is only supported if
+ # the underlining has the same size as the herder text.
+ # Found title
+ $wrapped_mode = 0;
+ my $level = $line;
+ $level =~ s/^(.).*$/$1/;
+ my $t = $self->translate($paragraph,
+ $self->{ref},
+ "Title $level",
+ "wrap" => 0);
+ $self->pushline($t);
+ $paragraph="";
+ $wrapped_mode = 1;
+ $self->pushline(($level x (length($t)-1))."\n");
+ } elsif ($markdown and
+ ($line =~ m/^(#{1,6})( +)(.*?)( +\1)?$/)) {
+ my $titlelevel1 = $1;
+ my $titlespaces = $2;
+ my $title = $3;
+ my $titlelevel2 = $4||"";
+ # Found one line title
+ do_paragraph($self,$paragraph,$wrapped_mode);
+ $wrapped_mode = 0;
+ $paragraph="";
+ my $t = $self->translate($title,
+ $self->{ref},
+ "Title $titlelevel1",
+ "wrap" => 0);
+ $self->pushline($titlelevel1.$titlespaces.$t.$titlelevel2."\n");
+ $wrapped_mode = 1;
+ } elsif ($markdown and
+ ($paragraph eq "") and
+ ($line =~ /^((\*\s*){3,}|(-\s*){3,}|(_\s*){3,})$/)) {
+ # Horizontal rule
+ $wrapped_mode = 1;
+ $self->pushline($line."\n");
} elsif ($line =~ /^-- $/) {
# Break paragraphs on email signature hint
do_paragraph($self,$paragraph,$wrapped_mode);
@@ -503,6 +605,15 @@ sub parse {
do_paragraph($self,$paragraph,$wrapped_mode);
$paragraph="$line\n";
$wrapped_mode = 1;
+ } elsif ($tabs eq "split" and $line =~ m/\t/ and $paragraph !~ m/\t/s) {
+ $wrapped_mode = 0;
+ do_paragraph($self,$paragraph,$wrapped_mode);
+ $paragraph = "$line\n";
+ $wrapped_mode = 0;
+ } elsif ($tabs eq "split" and $line !~ m/\t/ and $paragraph =~ m/\t/s) {
+ do_paragraph($self,$paragraph,$wrapped_mode);
+ $paragraph = "$line\n";
+ $wrapped_mode = 1;
} else {
if ($line =~ /^\s/) {
# A line starting by a space indicates a non-wrap
@@ -530,6 +641,8 @@ sub parse {
# are considered as verbatim paragraphs
$wrapped_mode = 0 if ( $paragraph =~ m/^(\*|[0-9]+[.)] )/s
or $paragraph =~ m/[ \t][ \t][ \t]/s);
+ $wrapped_mode = 0 if ( $tabs eq "verbatim"
+ and $paragraph =~ m/\t/s);
if ($markdown) {
# Some Markdown markup can (or might) not survive wrapping
$wrapped_mode = 0 if (