[Po4a-commits] r2602 - in /trunk: lib/Locale/Po4a/Text.pm po4a-gettextize
barbier at users.alioth.debian.org
barbier at users.alioth.debian.org
Sun Sep 30 22:38:09 UTC 2012
Author: barbier
Date: Sun Sep 30 22:38:08 2012
New Revision: 2602
URL: http://svn.debian.org/wsvn/po4a/?sc=1&rev=2602
Log:
AsciiDoc: fix two line titles when encoding is different from ascii
Two line titles consist of a title line followed by an underline, which
has the same width as the title line. We thus have to compute this
width, which requires knowing text encoding.
But text comes either from PO files or master documents. A simple
solution is to always take encoding from PO file, and modify po4a-gettextize
to artificially set $transtt->{TT}{po_in}{encoder}.
Text width is computed by the Unicode::GCString module. If this module
is not available and encoding is not ASCII, processing stops.
Modified:
trunk/lib/Locale/Po4a/Text.pm
trunk/po4a-gettextize
Modified: trunk/lib/Locale/Po4a/Text.pm
URL: http://svn.debian.org/wsvn/po4a/trunk/lib/Locale/Po4a/Text.pm?rev=2602&op=diff
==============================================================================
--- trunk/lib/Locale/Po4a/Text.pm (original)
+++ trunk/lib/Locale/Po4a/Text.pm Sun Sep 30 22:38:08 2012
@@ -375,6 +375,23 @@
my $asciidoc_RE_STYLE_LIST = "appendix|horizontal|qanda|glossary|bibliography";
my $asciidoc_RE_STYLES = "$asciidoc_RE_SECTION_TEMPLATES|$asciidoc_RE_STYLE_ADMONITION|$asciidoc_RE_STYLE_PARAGRAPH|$asciidoc_RE_STYLE_NUMBERING|$asciidoc_RE_STYLE_LIST|float";
+BEGIN {
+ if (eval { require Unicode::GCString }) {
+ eval 'sub columns($$$) {
+ my $text = shift;
+ my $encoder = shift;
+ $text = $encoder->decode($text) if (defined($encoder) && $encoder->name ne "ascii");
+ return Unicode::GCString->new($text)->columns();
+ }';
+ } else {
+ eval 'sub columns($$$) {
+ return length($_[0]) if !defined($_[1]) || $_[1]->name eq "ascii";
+ die wrap_mod("po4a::text",
+ dgettext("po4a", "Detection of two line titles failed at %s\nInstall the Unicode::GCString module!"), $_[2])
+ }';
+ }
+}
+
sub parse_asciidoc {
my ($self,$line,$ref,$paragraph,$wrapped_mode,$expect_header,$end_of_paragraph) = @_;
if ((defined $self->{verbatim}) and ($self->{verbatim} == 2)) {
@@ -394,7 +411,7 @@
($line =~ m/^(={4,}|-{4,}|~{4,}|\^{4,}|\+{4,})$/) and
(defined($paragraph) )and
($paragraph =~ m/^[^\n]*\n$/s) and
- (length($paragraph) == (length($line)+1))) {
+ (columns($paragraph, $self->{TT}{po_in}{encoder}, $ref) == (length($line)))) {
# Found title
$wrapped_mode = 0;
my $level = $line;
@@ -407,7 +424,7 @@
$self->pushline($t."\n");
$paragraph="";
$wrapped_mode = 1;
- $self->pushline(($level x (length($t)))."\n");
+ $self->pushline(($level x (columns($t, $self->{TT}{po_in}{encoder}, $ref)))."\n");
} elsif ($line =~ m/^(={1,5})( +)(.*?)( +\1)?$/) {
my $titlelevel1 = $1;
my $titlespaces = $2;
Modified: trunk/po4a-gettextize
URL: http://svn.debian.org/wsvn/po4a/trunk/po4a-gettextize?rev=2602&op=diff
==============================================================================
--- trunk/po4a-gettextize (original)
+++ trunk/po4a-gettextize Sun Sep 30 22:38:08 2012
@@ -186,7 +186,7 @@
my ($pofile)=('-');
my (@masterfile, at locfile,$help_fmt,$help,$type, at options);
-my ($mastchar,$locchar);
+my ($mastchar,$locchar)=('ascii');
Getopt::Long::config('bundling', 'no_getopt_compat', 'no_auto_abbrev');
GetOptions(
'help|h' => \$help,
@@ -238,7 +238,11 @@
$mastertt->read($file);
}
$mastertt->{TT}{utf_mode} = 1;
-$mastertt->{TT}{file_in_charset} = $mastchar;
+if ($mastertt->{TT}{ascii_input}) {
+ $mastertt->detected_charset('ascii');
+} else {
+ $mastertt->detected_charset($mastchar);
+}
$mastertt->parse;
@@ -253,7 +257,8 @@
}
# We force the conversion to utf if the master document wasn't in ascii
$transtt->{TT}{utf_mode} = !$mastertt->{TT}{ascii_input};
- $transtt->{TT}{file_in_charset} = $locchar;
+ $transtt->detected_charset($locchar);
+ $transtt->{TT}{po_in}->set_charset($locchar);
$transtt->parse;
my $mergedpo = Locale::Po4a::Po->gettextize($mastertt->getpoout(),
More information about the Po4a-commits
mailing list