[RFC] Automatic localisation of templates

Simon Wistow simon at thegestalt.org
Thu Jan 19 12:22:56 GMT 2006


I've written a plugin for TT that, given this

	[%- USE Localisation('MyTranslation') -%]
	[%- SET foo = "_GREETING_" -%]
	[% foo %]
	[% "_GREETING_" %]

and a Locale::MakeText lexicon module called 'MyTranslation' which 
contains an entry for __GREETING__ mapping to 'Hello' 

prints

	Hello
	Hello

and changing the first line to

	[%- USE Localisation('MyTranslation','fr') -%]

prints (providing you've provided a french lexicon)

	Bonjour
	Bonjour

Obviously something like 

    [% USE CGI %]
	[% USE Localisation('MyTranslation',CGI.http('Accept-language')) %]

would be very useful.

Strings not in the lexicon are left untranslated. 

There's still a couple of issues to be sorted out and I'm not convinced
that Locale::MakeText is the right il8n module to use for various
reasons (it's really good but a litle too complicated to use the
advanced parts of it. Easier than making .po files though) but I think
this could be really useful for doing multi language websites.

Unfortunately, at the moment, it requires you to create your TT object 
like this

my $tt = Template->new({
             FACTORY => "Template::Directive::Localisation" 
         });


I'm currently pondering whether to try to make it so that when you load 
the plugin then it auto replaces the current context's Directive but I'm 
not sure that that's actually possible. Perhaps having a 
Template::Localisation object that's a sub class of Template.pm would be 
better.

Comments and suggestions are very welcome.

Simon

-- 
rorshach and prozac and everything's groovy



More information about the london.pm mailing list