Re: HTML::Template and Locale::Maketext

David Baxter <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.cgi-appplication,gmane.comp.lang.perl.modules.html-template
Message-ID <[email protected]>
Hi Johan,

Johan Kuuse wrote:

>Hi,
>
>This is a long post, so feel free to stop reading now. :-)
>
>Anyone has used HTML::Template and Locale::Maketext together?
>Or HTML::Template in any I18N project?
>
>My doubts are mostly what approach I should use.
>The application I planning to start is not that big, but I always liked 
>separating things:
>a. .pl files - For the Perl programmer.
>b. .html files - for the web designer
>c. .po and/or .pm files containing just languages hashes - for the language 
>translator (ok, Perl hashes, but very readable even for a non-programmer)
>
>To keep things separated, there is a problem:
>1. If, on one hand, I want to use one single HTML::Template for the output in 
>different languages, the template itself cannot have any "fixed strings" in 
>one languages, but has to be filled up only with <TMPL_VAR NAME=xxx> tags for 
>every single message.
>This makes the job tougher for the web designer (the web page preview will be 
>almost unreadable).
>2. If, on the other hand, one HTML::Template per language, the translator has 
>to know some HTML to create a HTML::Template with "fixed strings" in her/his 
>language. And this means that the web designer will end up with one template 
>per language, which also is undesirable.
>
>  
>
If one of your main concern is how the web designer will be able ot view
the designs (which is a valid concern) you could simply instruct them to
place the 'original' text within a bogus TMPL_IF condition that never
gets called, e.g.

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<title><TMPL_VAR NAME=HELLO_WORLD><TMPL_IF default>Hello World!</TMPL_IF></title>
</head>
<body>
<b><TMPL_VAR NAME=HELLO_WORLD><TMPL_IF default>Hello World!</TMPL_IF></b>
<p><TMPL_VAR NAME=WELCOME_TO_THIS_WEB_SITE><TMPL_IF default>Welcome to this web site.</TMPL_IF></p>
</body>
</html>


When the designer views their page, they will see it as it will appear
with English text. Admittedly, this may be a little more difficult to
read when viewing the code.

Regards,

David

>Any suggestions are appreciated.
>
>I will try explaining details of the problem by using a couple of examples:
>
>Approach 1, using one template for all languages:
>hello.pl
># ----------------------------------------
>#!/usr/bin/perl -w
>use HTML::Template;
>use MyApp:I18N;
>my $locale = $ARGV || 'en'; # Use English as default
>my $lh = MyApp::I18N->get_handle($locale) || die "Can't get a language 
>handle!";
># open the html template
>my $template = HTML::Template->new(filename => 'hello.world.tmpl.html');
># fill in some parameters
>$template->param(
>	HELLO_WORLD => $lh->maketext("Hello, world!"),
>	WELCOME_TO_THIS_WEB_SITE => $lh->maketext("Welcome to this web site."),
>);
># send the obligatory Content-Type and print the template output
>print "Content-Type: text/html\n\n", $template->output;
># ----------------------------------------
>hello.world.tmpl.html
># ----------------------------------------
><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
><html>
><head>
><title><TMPL_VAR NAME=HELLO_WORLD></title>
></head>
><body>
><b><TMPL_VAR NAME=HELLO_WORLD></b>
><p><TMPL_VAR NAME=WELCOME_TO_THIS_WEB_SITE></p>
></body>
></html>
># ----------------------------------------
>MyApp/I18N/en.pm
># ----------------------------------------
>package MyApp::I18N::es;
># Spanish language messages
>use base qw(MyApp::I18N);
>use strict;
>use vars qw(%Lexicon);
>%Lexicon = (
>  # Message to translator: Start here!
>  "Hello, world!" => "Hello, world!",
>  "Welcome to this website." => "Welcome to this website.",
>  # Message to translator: Stop here!
>);
># ----------------------------------------
>MyApp/I18N/es.pm
># ----------------------------------------
>package MyApp::I18N::es;
># Spanish language messages
>use base qw(MyApp::I18N);
>use strict;
>use vars qw(%Lexicon);
>%Lexicon = (
>  # Mensaje a traductor: ¡Empieza aquí!
>  "Hello, world!" => "¡Hola, mundo!",
>  "Welcome to this website." => "Bienvenido a este sitio web.",
>  # Mensaje a traductor: ¡Termina aquí!
>);
># ----------------------------------------
>MyApp/I18N/se.pm
># ----------------------------------------
>package MyApp::I18N::es;
># Swedish language messages
>use base qw(MyApp::I18N);
>use strict;
>use vars qw(%Lexicon);
>%Lexicon = (
>  # Meddelande till  översättaren: Börja här!
>  "Hello, world!" => "Hej, världen!",
>  "Welcome to this website." => "Välkommen till den här webbsajten.",
>  # Meddelande till  översättaren: Sluta här!
>);
># ----------------------------------------
>
>
>Approach 2, using one template per language:
>hello.pl
># ----------------------------------------
>#!/usr/bin/perl -w
>use HTML::Template;
>my $locale = $ARGV || 'en'; # Use English as default
>my $filename = 'hello.world.tmpl.html.' . $locale;
># open the html template
>my $template = HTML::Template->new(filename => $filename);
># send the obligatory Content-Type and print the template output
>print "Content-Type: text/html\n\n", $template->output;
># ----------------------------------------
>hello.world.tmpl.html.en
># ----------------------------------------
><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
><html>
><head>
><title>Hello, world!</title>
></head>
><body>
><b>Hello, world!</b>
><p>Welcome to this website.</p>
></body>
></html>
># ----------------------------------------
>hello.world.tmpl.html.es
># ----------------------------------------
><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
><html>
><head>
><title>¡Hola, mundo!</title>
></head>
><body>
><b>¡Hola, mundo!</b>
><p>Bienvenido a este sitio web.</p>
></body>
></html>
># ----------------------------------------
>hello.world.tmpl.html.se
># ----------------------------------------
><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
><html>
><head>
><title>Hej, världen!</title>
></head>
><body>
><b>Hej, världen!</b>
><p>Välkommen till den här webbsajten.</p>
></body>
></html>
># ----------------------------------------
>
>
>Best Regards,
>Johan Kuuse
>
>
>---------------------------------------------------------------------
>Web Archive:  http://www.mail-archive.com/[email protected]/
>              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
>To unsubscribe, e-mail: [email protected]
>For additional commands, e-mail: [email protected]
>
>
>
>  
>


---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/[email protected]/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.