[Catalyst] getting TT to translate automatically

Mark Blythe list at markblythe.com
Sun Apr 9 19:32:40 CEST 2006


I haven't tried this, but it looks like you could create a sub-class of
Template::Stash and override the get() method.  You could then use the STASH
config variable to get TT to use your custom class:

STASH : Reference to a custom stash object (default: Template::Stash).

I've been planning to use a lookup routine for localization.  So in my
templates, I'd do something like:

[% itext('foo') %]

Personally, I prefer the explicit lookup better since it's more clear what
is going on.  It also makes it posible to look up strings when their names
are stored in a string:

[% itext($name) %]

Implicit magic tends to complicate debugging, too.

Different strokes for different folks though.  :)


On 4/9/06, Daniel McBrearty <danielmcbrearty at gmail.com> wrote:
>
> Hi
>
> I am looking at using TT with cat to rewrite my multilanguage website.
>
> The way my current implementation works is that all text for the site is
> in a database, each row has a text mnemonic as primary key. You get back
> text in a given language by doing something like::
>
> $text = Sitetext::get( $lang, $key);
>
> You can also do substitution of variables like this :
>
> $text = Sitetext::get( $lang, $key, {NAME => "Pierre"});
>
>
> What I'd like to do is get TT to do this automatically for all items on
> the page that it doesn't find in the stash. So, for a template called "
> hello.tt" like this :
>
> <body>
> <H1>[%HELLO%]</H1>
> </body>
>
> and passed a stash like this :
>
> { substrings = {NAME => "Pierre"},
>   lang => "fr",
>   template => "hello.tt"}
>
> TT would then do Sitetext::get( 'fr', 'HELLO', {NAME => 'Pierre'} ),
> returning "Bonjour Pierre", and substitute it (because the HELLO var was not
> explicitly defined on the stash).
>
> Can anyone tell me if this is doable in TT? I have looked but don't see an
> easy way. Discussion of other neat methods used to make a multilingual
> catalyst app are also welcome ...
>
> regards
>
> Daniel
>
> --
> Daniel McBrearty
> email : danielmcbrearty at gmail.com
> www.engoi.com : the multi - language vocab trainer
> BTW : 0873928131
>
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20060409/097bd6df/attachment.htm 


More information about the Catalyst mailing list