From: Andreas Schwarz Date: 2004-03-08T06:24:41+09:00 Subject: Re: Looking for HTML templating system Kirk Haines wrote: > On Mon, 8 Mar 2004, Andreas Schwarz wrote: > > > I am looking for a templating system for my forum > > (http://rforum.rubyforge.org). I would prefer something lightweight > > like PageTemplate over heavy XML stuff like Amrita, because the > > forum will have to handle quite a lot of traffic and my server > > doesn't have too much memory. But the reason why I can't use most of > > the templating engines is that I want to make the forum > > multi-language, so that I can't write: > > > > [%if logged_in%] > > Logged in as [%var username%] > > [%endif%] > > > > but would have to write something like > > > > [%if logged_in%] > > [%var text_logged_in_as(username)%] > > [%endif%] > > > > Does anyone know a templating system I could use? > > Iowa might work. Thanks, I'll have a look at it. > How much traffic do you get, and what is your server's mem and CPU, > out of curiosity? At the moment I am using an extremely simple self-written PHP forum which gets about 500-600k hits per month (www.mikrocontroller.net/forum/). The typical loading time is < 0.2s, and I dont't want it to increase. The server is a virtual(UML) server from www.vd-server.de with 96MB RAM. > In HTML file: > > > @text_logged_in_as > > > > > In code file: > > def text_logged_in_as > # No idea how you are handling the multiple languages. > # The assumption here is that language choice is either stored > # in a cookie or derived from the HTTP_ACCEPT_LANG paramter, > # and that whichever way it's determined, we put the choice in a > # variable, @lang. Also assuming, for this example, that there's > # a big hash that contains the text items. > > @site_text[@lang]['logged_in_as'] > end I don't want to create a method for every string, and there is another problem: the strings have to take "arguments" (the username, in this case). I could use ERuby with a method like this: def gettext(string, *args) @text[@lang] % args end where @text[@lang] is "Logged in as %s". But it looks a bit ugly to have <%=gettext('LOGGED_IN_AS', @username)%> everywhere in the file... Another idea I just got: writing TEXT_LOGGED_IN_AS(username) in the template file and using a script to generate the different language versions of the template. > ----- > Another way would be to have more than one HTML file; one for each > language. I don't want to do that because it would mean writing a lot of redundant code. > This is how I'd probably do it, personally. If you go to > http://enigo.com/demos/multi_lang/index.html > there is a very quick, simple demo of this. I'd been planning to do > one, and your query gave me the impetus to do it. If you look at that > page with your langauge preference set to English, you'll see the > content in English. If you switch your preference to Spanish, you'll > see it in Spanish. I think I could use the accept-language setting to set the language cookie and also add some small form field to allow the user to change the language, because many browsers aren't configured correctly. Andreas