[Po4a-devel]New module (Dia)

Martin Quinson mquinson@ens-lyon.fr
Fri, 21 May 2004 19:36:13 +0200


--bgLLobvf7eP6VP5c
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hello,

cool ! Thanks for this module, and for the comment on the project. I also
feel that po4a benefits of a good design (and am rather proud of it ;)

I will include it to the next release, but in fact I was waiting for your
feedback on the CVS version before releasing it. Could you detail again what
your problem are with this version so that I get a chance to fix them soon?

About the encoding issues, that's one of the biggest issue in po4a, and I
hope that Denis will have some time to investigate this area during the
sommer...

Last point, the best would be if you could provide some sort of test case
for this new module, just like the ones provided for the man module. I plan
to add tests for each modules. The fact that most of them are missing for
now is seen as a bug... But that's not a blocker, and unless my checks
reveal some major issue, I'll include this to next release anyway.

Thanks for your time, Mt.

On Fri, May 21, 2004 at 07:26:32PM +0200, Jordi Vilalta wrote:
> Hi,
>=20
> this week I had my first contact with perl. I took the simplest po4a=20
> module I found (Html) and began changing things. The result has been the=
=20
> support for a new format: the uncompressed Dia diagrams.
>=20
> I've been testing it with the diagrams of a document I'm writing, and it=
=20
> works very well for me (although it needs more testing). I'm sure it's no=
t=20
> perfect, since those are my first lines written in perl. It would be nice=
=20
> if somebody could check it.
>=20
> I hope you find it useful. The Dia diagrams are very interesting for=20
> technical documentation, and the last version of Dia can export good=20
> quality pngs (and other formats) without needing X. It's nice to have a=
=20
> makefile automaticaly generating images in several languages from the=20
> original diagrams ;)
>=20
> I have to thank you (Denis and Martin) for beginning this great project=
=20
> (po4a) and taking this to its current status. I was surprised by how easy=
=20
> it is to add support for a new format using the packages you wrote :)=20
> Don't give up!
>=20
> When I have some free time I'll try to understand the Sgml module to help=
=20
> you improve it.
>=20
> Regards,
>=20
> Jordi Vilalta
>=20
>=20
> PS: Martin, about the last mail I wrote, there were more issues apart=20
> from the missing files in CVS. I just want to make sure you saw them, I=
=20
> don't want to rush you :P
> #!/usr/bin/perl
>=20
> # Po4a::Dia.pm=20
> #=20
> # extract and translate translatable strings from Dia diagrams.
> #=20
> # This code extracts plain text from string tags on uncompressed Dia
> # diagrams.
> #
> # Copyright (c) 2004 by Jordi Vilalta  <jvprat@wanadoo.es>
> #
> # This program is free software; you can redistribute it and/or modify
> # it under the terms of the GNU General Public License as published by
> # the Free Software Foundation; either version 2 of the License, or
> # (at your option) any later version.
> #
> # This program is distributed in the hope that it will be useful,
> # but WITHOUT ANY WARRANTY; without even the implied warranty of
> # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> # GNU General Public License for more details.
> #
> # You should have received a copy of the GNU General Public License
> # along with this program; if not, write to the Free Software
> # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
> #
> ########################################################################
>=20
> =3Dhead1 NAME
>=20
> Locale::Po4a::Dia - Convert uncompressed Dia diagrams from/to PO files
>=20
> =3Dhead1 DESCRIPTION
>=20
> The goal po4a [po for anything] project is to ease translations (and more
> interestingly, the maintenance of translation) using gettext tools on are=
as
> where they were not expected like documentation.=20
>=20
> Locale::Po4a::Dia is a module to help the translation of diagrams in the
> uncompressed Dia format into other [human] languages.
>=20
> You can get Dia (the graphical editor for these diagrams) from:
>   http://www.gnome.org/projects/dia/
>=20
> =3Dhead1 TRANSLATING WITH PO4A::DIA
>=20
> This module only translates uncompressed Dia diagrams.  You can save your
> uncompressed diagrams with Dia itself, unchecking the "Compress diagram
> files" at the "Save Diagram" dialog.
>=20
> Another way is to uncompress the dia files from command line with:
>   gunzip < original.dia > uncompressed.dia
>=20
> =3Dhead1 STATUS OF THIS MODULE
>=20
> It Works For Me (tm).  Currently it only searches for translateable strin=
gs,
> 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 con=
tens
> of the <dia:string> tags, but it seems to be all the text present at the
> diagrams.
>=20
> It skips the contens of the <dia:diagramdata> tag because there are usual=
ly
> some strings that are for internal use of Dia (not interesting for transl=
ation).
>=20
> Currently it tries to get the diagram encoding from the first line (the x=
ml
> declaration), and else it assumes UTF-8, and creates the .po contens in t=
he
> 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.
>=20
> 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.1=
0/
> There may be a better or more standard module to do this, but I didn't kn=
ow.
> You're welcome to improve it.
>=20
> This module should work, and it shouldn't break anything, but it needs mo=
re
> testing.
>=20
> =3Dhead1 SEE ALSO
>=20
> L<po4a(7)>, L<Locale::Po4a::TransTranctor(3pm)>, L<Locale::Po4a::Pod(3pm)=
>.
>=20
> =3Dhead1 AUTHORS
>=20
> Jordi Vilalta <jvprat@wanadoo.es>
>=20
> =3Dhead1 COPYRIGHT AND LICENSE
>=20
> Copyright (c) 2004 by Jordi Vilalta  <jvprat@wanadoo.es>
>=20
> This program is free software; you may redistribute it and/or modify it
> under the terms of GPL (see COPYING file).
>=20
> =3Dcut
>=20
> package Locale::Po4a::Dia;
>=20
> use 5.006;
> use strict;
> use warnings;
>=20
> require Exporter;
> use vars qw(@ISA @EXPORT);
> @ISA =3D qw(Locale::Po4a::TransTractor);
> @EXPORT =3D qw(new initialize);
>=20
> use Locale::Po4a::TransTractor;
> use Locale::gettext qw(gettext);
> #is there any better (or more standard) package than this to recode strin=
gs?
> use Locale::Recode;
>=20
> sub initialize {}
>=20
> sub read {
> 	my ($self,$filename)=3D@_;
> 	push @{$self->{DOCPOD}{infile}}, $filename;
> 	$self->Locale::Po4a::TransTractor::read($filename);
> }
>=20
> sub parse {
> 	my $self=3Dshift;
> 	map {$self->parse_file($_)} @{$self->{DOCPOD}{infile}};
> }
>=20
> #
> # Parse file and translate it
> #
> sub parse_file {
> 	my ($self,$filename)=3D@_;
> 	my ($line,$ref);
> 	my ($paragraph,$reference); #The text to be translated
>=20
> 	#Initializing the recoding objects
> 	#	d2p: dia to po
> 	#	p2d: po to dia
> 	my ($d2p,$p2d,$charset_dia,$charset_po);
>=20
> 	($line,$ref)=3D$self->shiftline();
> 	if (defined($line)) {
> 		#Try to get the document encoding from the xml header
> 		if ( $line =3D~ /<\?xml.*?encoding=3D"(.*)".*\?>/ ) {
> 			$charset_dia =3D $1;
> 		} else {
> 			#Dia's default is UTF-8
> 			$charset_dia =3D 'UTF-8';
> 			warn gettext("po4a::dia: Couldn't find file encoding. Assuming UTF-8."=
)."\n";
> 		}
> 		#how to get command line options to override it?
> 		$charset_po =3D 'ISO-8859-1';
>=20
> 		$d2p =3D Locale::Recode->new(from =3D> $charset_dia,
> 					to =3D> $charset_po);
> 		die $d2p->getError if $d2p->getError;
>=20
> 		$p2d =3D Locale::Recode->new(from =3D> $charset_po,
> 					to =3D> $charset_dia);
> 		die $p2d->getError if $p2d->getError;
> 	}
> 	while (defined($line)) {
> 		#don't translate any string between <dia:diagramdata> tags
> 		if ( $line =3D~ /^<dia:diagramdata>(.*)/s ) {
> 			$line =3D $1;
> 			$self->pushline("<dia:diagramdata>");
> 			while ( $line !~ /<\/dia:diagramdata>/ ) {
> 				$self->pushline($line);
> 				($line,$ref)=3D$self->shiftline();
> 			}
> 			$line =3D~ /(.*?<\/dia:diagramdata>)(.*)/s;
> 			$self->pushline($1);
> 			$line =3D $2;
> 		} else {
> 			if ( $line =3D~ /(.*?)(<dia:diagramdata>.*)/s ) {
> 				$self->unshiftline($2,$ref);
> 				$line =3D $1;
> 			}
> 		}
>=20
> 		#if current line has an opening <dia:string> tag, we get
> 		#all the paragraph to translate (posibly from next lines)
> 		if ( $line =3D~ /(.*?)<dia:string>#(.*)/s ) {
> 			#pushing the text before the tag as is
> 			$self->pushline($1);
>=20
> 			#save the beginning of the tag contens and its position
> 			$paragraph =3D $2;
> 			$reference =3D $ref;
>=20
> 			#append the following lines to the paragraph until we
> 			#find the closing tag
> 			while ( $paragraph !~ /.*#<\/dia:string>/ ) {
> 				($line,$ref)=3D$self->shiftline();
> 				$paragraph .=3D $line;
> 			}
> 			$paragraph =3D~ /(.*?)#<\/dia:string>(.*)/s;
> 			$paragraph =3D $1;
>=20
> 			#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);
>=20
> 			#recode the paragraph to the po character set
> 			$d2p->recode($paragraph);
> 			$paragraph =3D $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);
> 		}
>=20
> 		#get next line
> 		($line,$ref)=3D$self->shiftline();
> 	}
> }


--=20
Je crois que nous sommes dans une tendance irr=E9versible pour plus de
libert=E9 et de d=E9mocratie, mais =E7a pourrait changer.
  -- G.W. Bush

--bgLLobvf7eP6VP5c
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFArj4LIiC/MeFF8zQRArKbAKCxj3XLJkKg0BMqVcPWI7oX+MlJwACfR3/u
9Ts4sTdOX6TAQvjSHXtmydQ=
=vzrc
-----END PGP SIGNATURE-----

--bgLLobvf7eP6VP5c--