Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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
[stevieb]: I found that win10 broke a C# library I was using for one project while enhancing tests for a Perl dist, which breaks other Perl dists, and I'm about to throw my hands up on berrybrew. win2k12 broke one thing, win10 breaks something...
[stevieb]: ...unrelated which requires replacing a lot of code and a whole lib. I'm about to go nix only ffs
[shmem]: stevieb: what you're doing sounds afwully complex. Too much for me this evening to provide brighter insight ;-)
[stevieb]: I don't even own a Windows computer. Both my girl and I have a laptop each with Linux. I'm supporting Windows in some of my projects and I can't even guage whether it's worth it or not.
[stevieb]: shmem It's something I desired to have years ago, which is why I took over berrybrew. Cross-platform build/test automation locally, or over the network Test::BrewBuild
[shmem]: sounds good.
[shmem]: but I'm crumbling smaller stones. remember...
[stevieb]: I'm working on it to fatten it up and make it more reliant so I can finalize my Raspberry Pi automated build system for that software :) It's all well and fun, until I try to make it work with Windows lol
[shmem]: "debugging a program is more difficult than to write it in the first place. If you code your program as smart as you are, you are, by definition, too dumb to debug it."

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2017-03-28 22:07 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (342 votes). Check out past polls.