Thread: [htmltmpl] language support
Brought to you by:
samtregar
From: Martin S. <sa...@ic...> - 2004-08-24 11:09:51
|
Hi folks, I lack multiple language support in HTML::Template. My idea is that I wrote complete HTML page with tons of design included and then wrap pieces of text using e.g. <TMPL_LANG lang="eng">Hello</TMPL_LANG> <TMPL_LANG lang="spa">Ciao</TMPL_LANG> <TMPL_LANG lang="cze">Ahoj</TMPL_LANG> How do you solve this problem? Using <TMPL_IF lang=""> construct isn't appropriate for several reasons: -- $lang is not accessible in <TMPL_LOOP> context -- it's too clumsy for manual writting -- <TMPL_IF> is not 'system' solution, it cannot handle e.g. substitution of similar languages or so. Creating another copy of template file with translation is not maintainable because of changes in design. Or should I use GNU gettext in some way? Thanks a lot for advice -- Martin Sarfy |
From: Sam T. <sa...@tr...> - 2004-08-24 16:07:35
|
On Tue, 24 Aug 2004, Martin Sarfy wrote: > Using <TMPL_IF lang=""> construct isn't appropriate for several reasons: > > -- $lang is not accessible in <TMPL_LOOP> context Use global_vars and it will be. > -- it's too clumsy for manual writting I don't understand what you mean by this. If you consider HTML::Template's syntax to be too clumsy then why are you using it? > -- <TMPL_IF> is not 'system' solution, it cannot handle e.g. > substitution of similar languages or so. You can handle that in your code. I'm certainly not going to add an exhaustive list of languages and their synonyms to HTML::Template! > Or should I use GNU gettext in some way? Possibly. I've seen it used in similar situations, but I've never used it myself. -sam |
From: Martin S. <sa...@ic...> - 2004-08-24 19:23:59
|
On Tue, Aug 24, 2004 at 12:07:32PM -0400, Sam Tregar wrote: > On Tue, 24 Aug 2004, Martin Sarfy wrote: > > > Using <TMPL_IF lang=""> construct isn't appropriate for several reasons: > > > > -- $lang is not accessible in <TMPL_LOOP> context > > Use global_vars and it will be. It's good that global_vars is not set by default, clean namespace in <TMPL_LOOP> is advantage and I don't want to turn it on only because translations. > > -- it's too clumsy for manual writting > > I don't understand what you mean by this. If you consider > HTML::Template's syntax to be too clumsy then why are you using it? Syntax is perfect because many designers are able to learn it and work of programmer and designer can be splitted, now I'm talking about work of translator, who needs some easy to understand/use syntax, he cannot write <TMPL_IF VAR="lang"> logic for every label he wants to translate. > > -- <TMPL_IF> is not 'system' solution, it cannot handle e.g. > > substitution of similar languages or so. > > You can handle that in your code. I'm certainly not going to add an > exhaustive list of languages and their synonyms to HTML::Template! > > > Or should I use GNU gettext in some way? > > Possibly. I've seen it used in similar situations, but I've never > used it myself. I can't imagine how to use it, how to enclose string in template file and how to call gettext() function (this has to be called from within HTML::Template code). I think ability to write templates in several languages is common requirement, so common that built-in support in templating engine should be considered. -- Martin Sarfy |
From: Alex K. <ka...@ra...> - 2004-08-25 08:53:58
|
* Martin Sarfy <sa...@ic...> [August 24 2004, 23:23]: > > > Using <TMPL_IF lang=""> construct isn't appropriate for several reasons: > > > -- $lang is not accessible in <TMPL_LOOP> context > > Use global_vars and it will be. > It's good that global_vars is not set by default, clean namespace in > <TMPL_LOOP> is advantage and I don't want to turn it on only because > translations. And global_vars slow down processing by a factor of 4. I once was very surprised with a profile where HTML::Template::output took more than 40% of execution time. -- Alex Kapranoff. |
From: <al...@lo...> - 2004-08-25 04:43:39
|
> On Tue, 24 Aug 2004, Martin Sarfy wrote: >=20 > Using <TMPL_IF lang=3D""> construct isn't appropriate for several = reasons: >=20 > -- $lang is not accessible in <TMPL_LOOP> context > -- it's too clumsy for manual writting > -- <TMPL_IF> is not 'system' solution, it cannot handle e.g. > substitution of similar languages or so. Hi Martin. You seem to be attacking your project with a sledgehammer. There is always an elegant solution hiding somewhere, but you have to slow down enough to look for it. Have you heard that tale of 2 programmers? They have an idea and one starts coding=20 The other sits down and thinks and plans and when the first is halfway = through,=20 the second starts coding and finishes first. His program works, is = extensible=20 and scalable and first one is reminiscent of spaghetti with a huge = dollop of lard in it. Alan. |
From: Markus S. <m.s...@gm...> - 2004-08-27 13:33:28
Attachments:
springm.vcf
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Martin Sarfy wrote: | Hi folks, | | I lack multiple language support in HTML::Template. My way to do it is as following: 1 Have Templates in one basic language 2 Use Locale::Maketext as basic functionality to retrieve localized text strings 3 Use template filters during load_tmpl to localize text between tags as well as text in certain tag attributes, especially alt="" and title="". Replacement strings come from Locale::Maketext 4 localize your variable values from inside your program before submitting those as template variables 3 is done by subclassing HTML::Template to recognize filter arguments as a part of the cache key (idea and code from Cees Hek), so that localization of the templates is done once before caching. If there is interest for this solution, I could pack up the code but it might take some days as I am in holidays. Kind regards Markus Spring -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFBLzgjxxUzQSse11ARAgPeAJwKUz/4IVcvGB1++tfrQlyozqUQpgCgjKki XLiJfJdKBow3zrpDNsP3oqQ= =I11g -----END PGP SIGNATURE----- |
From: Martin S. <sa...@ic...> - 2004-08-27 13:40:13
|
On Fri, Aug 27, 2004 at 03:33:23PM +0200, Markus Spring wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Martin Sarfy wrote: > | Hi folks, > | > | I lack multiple language support in HTML::Template. > > My way to do it is as following: > > 1 Have Templates in one basic language > 2 Use Locale::Maketext as basic functionality to retrieve localized text > strings > 3 Use template filters during load_tmpl to localize text between tags as > well as > text in certain tag attributes, especially alt="" and title="". Replacement > strings come from Locale::Maketext > 4 localize your variable values from inside your program before submitting > those > as template variables > > 3 is done by subclassing HTML::Template to recognize filter arguments as a > part > of the cache key (idea and code from Cees Hek), so that localization of the > templates is done once before caching. > > If there is interest for this solution, I could pack up the code but it > might > take some days as I am in holidays. Thanks, I'll do it this way. Happy holidays Martin |
From: Paul P. <pau...@fr...> - 2004-09-01 15:19:46
|
Martin Sarfy wrote: >Hi folks, > >I lack multiple language support in HTML::Template.=20 > =20 > Hi, (back from holidays, hence the late answer) The Koha project (www.koha.org) uses HTML::Template. and has several languages (english, french, polish, chinese, others to co= me) To do this, we wrote a script that create a .po file and create the translated templates from this po & the english templates. works quite fine. (look on sourceforge.net, projet koha, the script is hidden on koha/misc/translator/tmpl_process3.pl) --=20 Paul POULAIN Consultant ind=E9pendant en logiciels libres responsable francophone de koha (SIGB libre http://www.koha-fr.org) |