[Catalyst] Best prcatice: same back-end, different UI

Peter Edwards peter at dragonstaff.co.uk
Wed Mar 9 08:38:58 GMT 2011


On 9 March 2011 06:13, Jason Galea <lists at eightdegrees.com.au> wrote:

> assuming you are subclassing Catalyst::View::TT for your view you can do:
>  $c->stash->{additional_template_paths} =3D
> [$c->config->{root}.'/'.$theme_dir];
> in your controller, auto, chain, whatever. This will tell TT to look
> for templates there first.
>
>
You can also use http://search.cpan.org/perldoc?CatalystX::I18N
Set up your Catalyst configuration per the instructions there.
Detect locale using
http://search.cpan.org/perldoc?CatalystX::I18N::Role::GetLocale and extend
that if you want additional browser detection to affect the behaviour.
That will store the locale in the user session.
In the parameter hash you pass to Template Toolkit pass in a variable "loc"
that is a helper function that calls a localisation object made using
http://search.cpan.org/perldoc?CatalystX::I18N::Role::Maketext to call
maketext() from http://search.cpan.org/perldoc?Locale::Maketext to localise
messages according to the locale in the session, with a fallback to 'en' (or
your local language).
Call from .tt2 templates like
      <span class=3D"result">[% loc("You found [_1] of [_2] results",
results.hits, results.total) %]</span>
For the translations create .po files in the directories pointed to by the
parameters you gave
http://search.cpan.org/perldoc?CatalystX::I18N::Model::Maketext
Remember to also internationalise dates, times, currency formats.

Regards, Peter
http://perl.dragonstaff.co.uk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20110309/5be69=
f90/attachment.htm


More information about the Catalyst mailing list