Wow! This patch is great, i hope it makes it into the core.
I have tested stuff using the patch already (as i was searching for such
a solution - sent a few mails to the template regarding languages a few
weeks ago).
The patch has enable me to do simple things like:
In my template:
---------------
Hello in <tmpl_var name=language> is <lang>hello</lang>
-----------------------------------------
Then i have used the Locale::PGetText module and created my .po files
and then use the gettext method of PGetText and it works wonderfully.
eg code:
my $query = new CGI;
my $language_filter = sub {
my $text_ref = shift;
my $languages = shift;
$$text_ref =~
s#<LANG>([^<]*(?:(?!</LANG>)<[^<]*)*)</LANG>#Locale::PGetText::gettext($1)#oesxgi;
};
$template = new HTML::Template(
filename => "$template_filename",
die_on_bad_params => 0,
loop_context_vars => 1,
filter => {
sub => $language_filter,
format => 'scalar',
args => [scalar $query->param("language")],
},
);
$template->param(language => 'french');
The caching seems to be working great as well.
I can see many uses of the patch beyond languages (as it does allow
'arguments'/'parameters' to be sent to filters which in itself is a
fantastic feature add).
simran.
On Wed, 2002-07-03 at 12:07, Cees Hek wrote:
>
> I'm a long time user of HTML::Template, but this is my first message to
> the list.
>
> I've been trying to handle Language Translations in my web applications,
> and have come up with a method that works very cleanly with
> HTML::Template. All it requires is a small patch which I have included
> below.
>
> All the patch does is allow you to pass a variable or list of variables
> to a filter. This in turn allows you to do thing like the following:
>
>
> my $filter = sub {
> my $text_ref = shift;
> my $language = shift;
> my $tr = new My::Translator(language => $language)
> # Send anything in between <LANG> tags for translation
> $$text_ref =~
> #<LANG>([^<]*(?:(?!</LANG>)<[^<]*)*)</LANG>#$tr->get($1)#oesxgi;
> };
> my $template = HTML::Template->new(filename => 'sample.tmpl',
> filter => {
> sub => $filter,
> format => 'scalar',
> args => ['fr']
> }
> );
>
>
> [snip snip >8 >8]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]