[Po4a-devel][CVS] po4a/lib/Locale/Po4a TransTractor.pm,1.27,1.28

Jordi Vilalta po4a-devel@lists.alioth.debian.org
Thu, 05 Aug 2004 12:20:01 +0000


Update of /cvsroot/po4a/po4a/lib/Locale/Po4a
In directory haydn:/tmp/cvs-serv2275

Modified Files:
	TransTractor.pm 
Log Message:
First small step towars the encoding support :)
Detect if the input document has non-ascii characters


Index: TransTractor.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/TransTractor.pm,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- TransTractor.pm	29 Jul 2004 01:27:51 -0000	1.27
+++ TransTractor.pm	5 Aug 2004 12:19:59 -0000	1.28
@@ -21,6 +21,8 @@
 
 use Locale::gettext qw(dgettext);
 
+use Encode::Guess;
+
 =head1 NAME
 
 Po4a TransTractor - Generic trans(lator ex)tractor.
@@ -307,6 +309,8 @@
     if (defined $options{'debug'}) {
 	$self->{TT}{debug}  =  $options{'debug'};
     }
+    # Input document is in ascii until we prove the opposite (in read())
+    $self->{TT}{ascii_input}=1;
 
     ## initialize the plugin
     $self->initialize(%options);
@@ -344,6 +348,15 @@
 	my $ref="$filename:$linenum";
 	my @entry=($textline,$ref);
 	push @{$self->{TT}{doc_in}}, @entry;
+
+	# Detect if this file has non-ascii characters
+	if($self->{TT}{ascii_input}) {
+	    my $decoder = guess_encoding($textline);
+	    if (!ref($decoder) or $decoder !~ /Encode::XS=/) {
+	        # We have detected a non-ascii line
+		$self->{TT}{ascii_input} = 0;
+	    }
+	}
     }
     close INPUT 
 	or croak (sprintf(dgettext("po4a","Can't close %s after reading: %s"),$filename,$!)."\n");