-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi list,
I have written a module provisionally named HTML::Translator which allows translation/internationalization of templates by means of Locale::Maketext and HTML::Parser. It's not ripe for CPAN yet, in the meantime you can download it from http://dream.lrrl.arch.tu-muenchen.de/~springm/perl/HTML-Translator-0.01.tar.gz There is an example included which shows the principal functionality, and I use it quite successful for a beta CGI::Application mapserver program. To translate a template file you simply make HTML::Translator part of your H::T->new filter like this: - --------------------------------------------------------------------- use YourFancyModule::L10n; use HTML::Translator; use vars qw/$LH/; ... sub cleanfilter { my $text_ref = shift; htmltrans($text_ref, $LH) if $LH; # now replace tmpl_var='' attributes to correct H::T syntax $$text_ref =~ s/tmpl_var=['"]?([^'"\s>]*)['"]?/<tmpl_var name='$1'>/msgio; return $text_ref; } sub lhfail { #print STDERR "RGUmapserver: No translation for '$_[1]'\n"; $_[1]; } $LH = YourFancyModule::L10n->get_handle($self->query->param('lang')) or die "could not make language handle for $langcode: $!"; $LH->fail_with( \&lhfail ); my $filter = sub { $self->cleanfilter(@_) }; my $tmpl = HTML::Template->new(... filter => $filter,); - --------------------------------------------------------------------- This module raises some H::T specific issues: * HTML::Parser can not parse H::T attribute constructs for HTML-4 like ' checked' values in checkboxes, <input name='x' type='checkbox' <tmpl_var x_checked>> where you cannot put checked='checked' for backwards compatibility. This is why I write such attributes as <input name='x' type='checkbox' tmpl_var='x_checked'> and later substitute them again by H::T correct syntax. Q: Is this reasonable? * H::T needs template files if you want to use caching - which is necessary as translating adds processing time but has to be done only once for every template. At the moment I plan to link my template files to country specific versions, but this will clutter the directory without real necessity. Q: What alternatives are possible? * Cached translated templates depend not only on the modification time of the template file but as well on the dictionary module. I tried to read the code of the caching mechanism but was not able to introduce a hook which might be able to react on changes of the dictionary module. Q: Is there guru's advice for the solution of this problem? * Finally the name: is HTML::Translator reasonable, or better HTML::Template::Translator or Locale::Maketext::HTMLtrans or s.e.b.? Any feedback will be appreciatiated. Markus -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: Processed by Mailcrypt 3.5.6 and Gnu Privacy Guard <http://www.gnupg.org/> iD8DBQE+btVkxxUzQSse11ARAkjPAJ0W6YwTo3vZPm6cPqDbbOyjtbAduACZAfqO RODlfRt3CDe1eqsYTfn5FKQ= =OVeV -----END PGP SIGNATURE----- ------------------------------------------------------- This SF.net email is sponsored by:Crypto Challenge is now open! Get cracking and register here for some mind boggling fun and the chance of winning an Apple iPod: http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en _______________________________________________ Html-template-users mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/html-template-users
