Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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..


Comment on Re: Template::Toolkit, look-and-feel and internationalization
Select or Download Code
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.

    Chris
    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.

        Nice! Learn something new every day...

        Chris
        M-x auto-bs-mode

        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%]?

        daniel

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://466232]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-07-23 02:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (131 votes), past polls