Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

HTML::Template and translations

by mce (Curate)
on Jan 15, 2010 at 08:48 UTC ( #817582=perlquestion: print w/replies, xml ) Need Help??

mce has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,
It has been a very long time I have posted something, however, I kept on programming in Perl

I wrote a nice application in Mod_Perl, CGI::Application and HTML::Template.

There are several templates and several runmodes.

Now I want to provide the interface in other languages, so I need to translate the templates.
What is the best way to do this? I can copy the entire template directory and provide full translations of each template. This is OK, but whenever I make an update in a template, I have to do it in all translations.

Or, I can make HTML::Template variables for each line in the template, which means that I have hunderds of parameters to manage?

Any thoughts?

Dr. Mark Ceulemans
sr. Security Consultant
Evidian, Belgium

Replies are listed 'Best First'.
Re: HTML::Template and translations
by jethro (Monsignor) on Jan 15, 2010 at 12:23 UTC

    localization/internationalization support generally runs unter the name L10N and I18N. Under Linux the gnu library gettext provides functions to translate strings from one language into other languages through a pregenerated database

    In perl the library can be accessed through Locale::gettext for example. Another approach would be Locale::Maketext, the reasons for this more programmatic approach are detailed in Locale::Maketext::TPJ13

    If you are lucky and have only fixed strings you could pregenerate the templates after any change to the templates, but normally you would have to add the translate step to your templating

    PS: There is HTML::Template::Compiled::Plugin::I18N

    UDPATE: You migh also want to read for a critique of the Maketext approach

    UPDATE: As dsheroh rightly commented it should be L10N, not I10N

      Just a minor correction: Shouldn't that be "L10N" for "localization"?

      And, since I'm here, I suppose I'll also throw in NLS (National/Native Language Support) and g11n (globalization) as other possible names for it.

Re: HTML::Template and translations
by amir_e_a (Hermit) on Jan 15, 2010 at 13:27 UTC

    I second the Locale::Maketext suggestion. I can also add that you really should:

    1. Separate your strings and your source files. Keep the strings in a separate file.
    2. Use Unicode everywhere. Save your source files, your template files and your strings files as Unicode. Make it UTF-8, unless you have a very good reason to use any other representation. see perlunicode.
    3. Even though it's a good idea to save your source files as UTF-8, it's even more important to keep your strings separately - and in UTF-8. I'm repeating myself, but it WILL save you a lot of trouble.

    (Edit: spelling.)

        Thanks a lot. A very interesting read. I never bothered to look beyond Maketext.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://817582]
Approved by Corion
Front-paged by Old_Gray_Bear
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2020-09-23 05:43 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (130 votes). Check out past polls.