Martin Sarfy wrote:
        <TMPL_LANG lang="eng">Hello</TMPL_LANG>
        <TMPL_LANG lang="spa">Ciao</TMPL_LANG>
        <TMPL_LANG lang="cze">Ahoj</TMPL_LANG>

The biggest problem with this, I find, is that if I use that solution the template now needs to contain all the messages in all the languages right there in the template. An update nightmare and quite messy.

Here is another suggestion:

I use gettext, and so I've created this filter:

my $gettextFilterSub = sub {
 my ($text_ref) = @_;
 $$text_ref =~
 s/<gettext\(\"([^\"]*)\"\)>/gettext($1)/ge; # To satisify xgettext: "
};

And then:
$template = HTML::Template->new(filename => $tFile,
                                filter => $gettextFilterSub)

Now, I can just type strings that are subject to translation directly in the template like:
<h1><gettext("My Project Title")></h1>
<gettext("Hello World")>


Using exactly the /<gettext\(\"([^\"]*)\"\)>/ format makes it possible
to use xgettext to extract the strings that need translation:

xgettext --c++ -o template.po template.tmpl

Now template.po contains entries for "My Project Title" and "Hello
World" that the translator can go right ahead and translate in a
separate file (completely standard GNU gettext and perl Locale::gettext
stuff ). If the translation is present it is used, otherwise the English
(or whatever) text is used.

I don't yet know how this works with caching, but I trust there is some
solution to that too... Cross that bridge when I get there... :-D

(I've just joined the mailing list and so I hope this ends up in the
right thread...)

Peter

P.S.: The magic I needed to get gettext to work was:
  ...
  # Or whatever language you like - We're in Denmark here...
  $ENV{LANG} = "da_DK";
  # I have a /tmp/da/LC_MESSAGES/proj.mo - created from .po with msgfmt
  bindtextdomain("proj","/tmp");
  # We can set the codeset explicitly or do so in a round-about way
  # using the LC_CTYPE...
  # setlocale(LC_CTYPE,"");
  bind_textdomain_codeset("proj", "ISO-8859-1");
  setlocale(LC_MESSAGES, "");
  textdomain("proj");
  ...
--
Peter Valdemar Mørch
http://www.morch.com


------------------------------------------------------- This Newsletter Sponsored by: Macrovision For reliable Linux application installations, use the industry's leading setup authoring tool, InstallShield X. Learn more and evaluate today. http://clk.atdmt.com/MSI/go/ins0030000001msi/direct/01/ _______________________________________________ Html-template-users mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/html-template-users

Reply via email to