[Po4a-commits] "po4a/lib/Locale/Po4a Xml.pm,1.51,1.52"

Nicolas FRANCOIS nekral-guest at alioth.debian.org
Mon Aug 6 22:13:56 UTC 2007


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

Modified Files:
	Xml.pm 
Log Message:
Add support for external entities in the Xml module.
(option includeexternal)


Index: Xml.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Xml.pm,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- Xml.pm	6 Jul 2007 18:28:34 -0000	1.51
+++ Xml.pm	6 Aug 2007 22:13:54 -0000	1.52
@@ -56,12 +56,55 @@
 
 use Locale::Po4a::TransTractor;
 use Locale::Po4a::Common;
+use Carp qw(croak);
 
 #It will mantain the path from the root tag to the current one
 my @path;
 
+#It will contain a list of external entities and their attached paths
+my %entities;
+
 my @comments;
 
+sub shiftline {
+    my $self = shift;
+    # call Transtractor's shiftline
+    my ($line,$ref) = $self->SUPER::shiftline();
+    return ($line,$ref) if (not defined $line);
+
+    for my $k (keys %entities) {
+        if ($line =~ m/^(.*?)&$k;(.*)$/s) {
+            my ($before, $after) = ($1, $2);
+            my $linenum=0;
+            my @textentries;
+
+            open (my $in, $entities{$k})
+                or croak wrap_mod("po4a::xml",
+                                  dgettext("po4a", "Can't read from %s: %s"),
+                                  $entities{$k}, $!);
+            while (defined (my $textline = <$in>)) {
+                $linenum++;
+                my $textref=$entities{$k}.":$linenum";
+                push @textentries, ($textline,$textref);
+            }
+            close $in
+                or croak wrap_mod("po4a::tex",
+                          dgettext("po4a", "Can't close %s after reading: %s"),
+                                  $entities{$k}, $!);
+
+            push @textentries, ($after, $ref);
+            $line = $before.(shift @textentries);
+            $ref .= " ".(shift @textentries);
+            while (@textentries) {
+                my ($r, $l) = (pop @textentries, pop @textentries);
+                $self->unshiftline($l,$r);
+            }
+        }
+    }
+
+    return ($line,$ref);
+}
+
 sub read {
 	my ($self,$filename)=@_;
 	push @{$self->{DOCPOD}{infile}}, $filename;
@@ -165,6 +208,13 @@
 It makes the tags and attributes searching to work in a case insensitive
 way.  If it's defined, it will treat E<lt>BooKE<gt>laNG and E<lt>BOOKE<gt>Lang as E<lt>bookE<gt>lang.
 
+=item includeexternal
+
+When defined, external entities are included in the generated (translated)
+document, and for the extraction of strings.  If it's not defined, you
+will have to translate external entities separately as independent
+documents.
+
 =item tagsonly
 
 Extracts only the specified tags in the "tags" option.  Otherwise, it
@@ -234,6 +284,7 @@
 	$self->{options}{'placeholder'}='';
 	$self->{options}{'doctype'}='';
 	$self->{options}{'nodefault'}='';
+	$self->{options}{'includeexternal'}=0;
 
 	$self->{options}{'verbose'}='';
 	$self->{options}{'debug'}='';
@@ -535,6 +586,10 @@
 				$part1.= $1;
 				$part2 = $2;
 				$file = 1;
+				if ($self->{options}{'includeexternal'}) {
+					$entities{$name} = $part2;
+					$entities{$name} =~ s/^"?(.*?)".*$/$1/s;
+				}
 			}
 			if ((not $file) and (not $includenow)) {
 			    if ($part2 =~ m/^\s*(["'])(.*)\1(\s*>.*)$/s) {




More information about the Po4a-commits mailing list