Re: Localizable template

From: Date: Mon, 07 Jun 2004 13:52:55 +0000
Subject: Re: Localizable template
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-12965@lists.php.net to get a copy of this message
On Mon, 2004-06-07 at 01:35 +0200, Stefan Neufeind wrote: > Do you just need to localise very few things? Otherwise maybe it > might be useful to separate the templates for all used languages. > E.g. it might be useful to have a separate menu-templatefile if you > decide to translate the menu. Same for content-pages etc. > > However, surely this doesn't answer your question about gettext and > HTML_Template_IT - however I can't help you with that engine, sorry. Well, this is what I have done: function gettextize_text($t) { $pos=0; $src=array(); $dst=array(); while (($beg=strpos($t, '_("', $pos))!==FALSE) { if (($end=strpos($t, '")', $beg+1))!==FALSE) { $substr=substr($t, $beg+3, $end-$beg-3); $src[]='_("'.$substr.'")'; $dst[]=_($substr); } $pos=$end; } return str_replace($src, $dst, $t);; } function template_from_file($file) { if (is_file(HTML_Template_Folder."/$file.tpl.html")) { $tpl=new HTML_Template_IT(HTML_Template_Folder); $contents=file_get_contents(HTML_Template_Folder."/$file.tpl.html"); $tpl->setTemplate(gettextize_text($contents), TRUE, FALSE); $tpl->setCurrentBlock(); return $tpl; } else return FALSE; } Isn't really cool and memory intensive, but it actually works and can be enhanced later. -HTH -- __________ | | | | Enver ALTIN (a.k.a. skyblue) | | Software developer, IT consultant | FRONT | |==========| FrontSITE Bilgi Teknolojisi A.Ş. |_____SITE_| http://www.frontsite.com.tr/

Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc
« previous php.pear.general (#12965) next »