[Catalyst] getting TT to translate automatically

Daniel McBrearty danielmcbrearty at gmail.com
Sun Apr 9 20:07:40 CEST 2006


my mind is going the same way, Mark, re having an explicit notation to say
"this needs localising". I've managed to make a simple plugin that takes
this:

[% sitetext.get('a_key') %]

and looks it up using the lang setting from the stash - it worked out pretty
easy, and made me say "ah!" ...

now I just want to make a macro around that so it can be called whatever you
want, like

[% l10n('a_key') %]

filters look quite promising too, as an alternative approach. TT is pretty
neat ...

Eventually I'd like to turn this lot into a plugn, so that you could define
a template, run a util script on it to populate your db/po files/whatever
... and then have nice web interface to manage/translate the whole lot via a
browser. I actually have quite a few bits of that around already ... we'll
see where it all leads.

cheers

D

On 4/9/06, Mark Blythe <list at markblythe.com> wrote:
>
> 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
>
>
>
>
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
>
>
>


--
Daniel McBrearty
email : danielmcbrearty at gmail.com
www.engoi.com : the multi - language vocab trainer
BTW : 0873928131
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20060409/4c1c7163/attachment-0001.htm 


More information about the Catalyst mailing list