[Po4a-devel][CVS] po4a/lib/Locale/Po4a Dia.pm,1.5,1.6
Jordi Vilalta
po4a-devel@lists.alioth.debian.org
Mon, 09 Aug 2004 16:21:51 +0000
Update of /cvsroot/po4a/po4a/lib/Locale/Po4a
In directory haydn:/tmp/cvs-serv13495
Modified Files:
Dia.pm
Log Message:
New Dia version (uses Xml.pm)
Index: Dia.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Dia.pm,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- Dia.pm 9 Aug 2004 12:58:30 -0000 1.5
+++ Dia.pm 9 Aug 2004 16:21:49 -0000 1.6
@@ -52,31 +52,14 @@
=head1 STATUS OF THIS MODULE
-It Works For Me (tm). Currently it only searches for translateable strings,
-without parsing the xml code around. It's quite simple, but it works, and
-gives a perfect output for valid input files. It only translates the content
-of the E<lt>dia:stringE<gt> tags, but it seems to be all the text present at the
-diagrams.
-
-It skips the content of the E<lt>dia:diagramdataE<gt> tag because there are usually
-some strings that are for internal use of Dia (not interesting for translation).
-
-Currently it tries to get the diagram encoding from the first line (the xml
-declaration), and else it assumes UTF-8, and creates the .po contens in the
-ISO-8859-1 character set. It would be nice if it could read the command line
-encoding options, but I haven't watched how to do it.
-
-It uses Locale::Recode from the package libintl to recode the character
-sets. You can get it from http://search.cpan.org/~guido/libintl-perl-1.10/
-There may be a better or more standard module to do this, but I didn't know.
-You're welcome to improve it.
-
-This module should work, and it shouldn't break anything, but it needs more
-testing.
+This module is fully functional, as it relies in the Locale::Po4a::Xml module.
+This only defines the translateable tags (E<lt>dia:stringE<gt>), and filters
+the internal strings (the content of the E<lt>dia:diagramdataE<gt> tag), not
+interesting for translation).
=head1 SEE ALSO
-L<po4a(7)|po4a.7>, L<Locale::Po4a::TransTractor(3pm)>, L<Locale::Po4a::Pod(3pm)>.
+L<po4a(7)|po4a.7>, L<Locale::Po4a::TransTractor(3pm)>, L<Locale::Po4a::Xml(3pm)>.
=head1 AUTHORS
@@ -97,119 +80,30 @@
use strict;
use warnings;
-require Exporter;
-use vars qw(@ISA @EXPORT);
-@ISA = qw(Locale::Po4a::TransTractor);
-@EXPORT = qw(new initialize);
-
-use Locale::Po4a::TransTractor;
-use Locale::gettext qw(gettext);
-#is there any better (or more standard) package than this to recode strings?
-use Locale::Recode;
+use Locale::Po4a::Xml;
-sub initialize {}
+use vars qw(@ISA);
+@ISA = qw(Locale::Po4a::Xml);
-sub read {
- my ($self,$filename)=@_;
- push @{$self->{DOCPOD}{infile}}, $filename;
- $self->Locale::Po4a::TransTractor::read($filename);
-}
+sub initialize {
+ my $self = shift;
+ my %options = @_;
-sub parse {
- my $self=shift;
- map {$self->parse_file($_)} @{$self->{DOCPOD}{infile}};
+ $self->SUPER::initialize(%options);
+ $self->{options}{'tagsonly'}=1;
+ $self->{options}{'tags'}.=' <dia:string>';
+ $self->treat_options;
}
-#
-# Parse file and translate it
-#
-sub parse_file {
- my ($self,$filename)=@_;
- my ($line,$ref);
- my ($paragraph,$reference); #The text to be translated
-
- #Initializing the recoding objects
- # d2p: dia to po
- # p2d: po to dia
- my ($d2p,$p2d,$charset_dia,$charset_po);
-
- ($line,$ref)=$self->shiftline();
- if (defined($line)) {
- #Try to get the document encoding from the xml header
- if ( $line =~ /<\?xml.*?encoding="(.*)".*\?>/ ) {
- $charset_dia = $1;
- } else {
- #Dia's default is UTF-8
- $charset_dia = 'UTF-8';
- warn "po4a::dia: ".dgettext("po4a","Couldn't find file encoding. Assuming UTF-8.")."\n";
- }
- #how to get command line options to override it?
- $charset_po = 'ISO-8859-1';
-
- $d2p = Locale::Recode->new(from => $charset_dia,
- to => $charset_po);
- die $d2p->getError if $d2p->getError;
+sub found_string {
+ my ($self,$text,$ref,$options)=@_;
- $p2d = Locale::Recode->new(from => $charset_po,
- to => $charset_dia);
- die $p2d->getError if $p2d->getError;
+ #We skip the paper type string
+ if ( $self->get_path() !~ /<dia:diagramdata>/ ) {
+ $text =~ /^#(.*)#$/s;
+ $text = "#".$self->translate($1,$ref,"String",
+ 'wrap'=>$self->{options}{'wrap'})."#";
}
- while (defined($line)) {
- #don't translate any string between <dia:diagramdata> tags
- if ( $line =~ /^<dia:diagramdata>(.*)/s ) {
- $line = $1;
- $self->pushline("<dia:diagramdata>");
- while ( $line !~ /<\/dia:diagramdata>/ ) {
- $self->pushline($line);
- ($line,$ref)=$self->shiftline();
- }
- $line =~ /(.*?<\/dia:diagramdata>)(.*)/s;
- $self->pushline($1);
- $line = $2;
- } else {
- if ( $line =~ /(.*?)(<dia:diagramdata>.*)/s ) {
- $self->unshiftline($2,$ref);
- $line = $1;
- }
- }
-
- #if current line has an opening <dia:string> tag, we get
- #all the paragraph to translate (posibly from next lines)
- if ( $line =~ /(.*?)<dia:string>#(.*)/s ) {
- #pushing the text before the tag as is
- $self->pushline($1);
-
- #save the beginning of the tag contens and its position
- $paragraph = $2;
- $reference = $ref;
-
- #append the following lines to the paragraph until we
- #find the closing tag
- while ( $paragraph !~ /.*#<\/dia:string>/ ) {
- ($line,$ref)=$self->shiftline();
- $paragraph .= $line;
- }
- $paragraph =~ /(.*?)#<\/dia:string>(.*)/s;
- $paragraph = $1;
-
- #put the text after the closing tag back to the input
- #(there could be more than one string to translate on
- #the same line)
- $self->unshiftline($2,$ref);
- #recode the paragraph to the po character set
- $d2p->recode($paragraph);
- $paragraph = $self->translate($paragraph,$reference,"<dia:string>");
- #recode the translation to the dia character set
- $p2d->recode($paragraph);
- #inserts translation to output
- $self->pushline("<dia:string>#".$paragraph."#</dia:string>");
- } else {
- #doesn't have text to translate: push line as is
- $self->pushline($line);
- }
-
- #get next line
- ($line,$ref)=$self->shiftline();
- }
+ return $text;
}