Re: [Phplib-users] Templates and i18n...
Brought to you by:
nhruby,
richardarcher
From: Aric C. <gre...@pe...> - 2002-12-03 18:39:24
|
> OK, I can see where you are going with this. I would approach this > slightly differently. > > I would build a database with the translations in it. Columns like: > lang char(2), # ISO country code > varname char(16), # contains the template varname > trans text, # the translated text > with indexes on lang and varname > > The template file would contain lots of tags like: > <h1>{TITLELABEL}</h1> > > You can extract all the template varnames from the template file with > a preg_match_all(). Then loop through the results generating a massive > SQL query which pulls all the text translations required for that page > out of the database with one query. Then loop through the SQL result > set and call $t->set_var($db->f('varname'), $db->f('trans')) for each > record. And that's why you have the getText() method which you can replace with whatever method you choose -- be it loading a language file or doing a SQL query. To support your method of doing a "massive SQL query" the getText() method could be required to accept a string or an array of all the strings in the template. I'm not sure of the most efficient way to do all this. I was thinking something like doing a preg_replace_callback() and using the getText() method as the callback. > > Your PHP script wouldn't even need to know the template varnames :) That's pretty much the whole idea. :) |