Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Template::Toolkit, look-and-feel and internationalization

by davidrw (Prior)
on Jun 13, 2005 at 17:39 UTC ( #466232=note: print w/replies, xml ) Need Help??

in reply to Template::Toolkit, look-and-feel and internationalization

We set up the language translation recently with TT -- here's how we did it (I'm not by any means claiming this is _THE_ way to do it.. not good or bad, just A way) (also, this wasn't too exciting because it was just for english-US vs english-UK):
  • Went through all the templates and wrapped all the text in a FILTER tag. So from: <div>Hello</div> to: <div>[% FILTER localize %]Hello[% END %]</div>
  • localize is setup in our custom TT modules. It bascially takes the text and treats it as a primary key. It gets the current locale from httpd.conf. Now, if it can find in a database table a value for that pk for that locale, it uses that. Otherwise it just returns the original text.
  • Had to populate these new locale tables with some translations.
I'm sure there's lots of pros and cons to be gleaned from the above, but keep in mind it was made for our more limited case..

Replies are listed 'Best First'.
Re^2: Template::Toolkit, look-and-feel and internationalization
by lachoy (Parson) on Jun 13, 2005 at 20:01 UTC

    How does the FILTER usage work when you've got to pass parameters?

    I've implemented something similar to this in OpenInteract2 -- you just call:

    [% MSG( 'somekey', param1, param2, ... ) %]

    ...and that call gets replaced by the relevant lookup and replacement. Behind the scenes it's using Locale::Maketext, but that detail is irrelevant to the template creator.

    M-x auto-bs-mode

      It's built to handle things like [% FILTER repeat(3) %]blah [% END %] -- Two starting points (with some good examples) are the FILTER directive and the Template::Filters docs.
        Just a little question... I saw that the | can be used for an alias to FILTER, but I didn't understood if this only applies to non-block directive... And if it's valid to remove the whitespaces... would the following be valid?
        • [%|i18n%]Text to be translated[%END%]
        • [%|i18n(10)%]You gained %d experience points[%END%]

        P.S.: Is there an alias for [%END%]?


        Nice! Learn something new every day...

        M-x auto-bs-mode

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://466232]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2018-02-19 03:52 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (258 votes). Check out past polls.