[Webdev] php localization

Donncha O Caoimh donncha.ocaoimh at tradesignals.com
Wed Dec 18 11:39:16 GMT 2002


I'd use Smarty. Here's how I might do it (off the top of my head)

1. Create Smarty template files, with all text replaced by smarty variables. 
You'll only need one template for all languages.
2. Enable caching, and use the language as part of the cache key for each 
template file.
3. For each language, have a php file which assigns the localized text to 
Smarty variables.
4. In your template container php script (say, page.inc.php) check if the 
Smarty template file is cached for the language requested, if not, then 
include the language php file (which assigns the Smaty variables).
5. Display the template then.
You'll also want to look up insert functions.

ie.

if( $smarty->is_cached( 'top.tpl', $lang ) == false )
{
  include( $lang . "inc.php" );
}

$smarty->display( 'top.tpl', $lang );

Smarty can also read data from a db or anywhere else, since the template files 
will be cached 99.99% of the time you could have a nice interface for 
manipulating a db..

Ok, it's a bit complicated, but http://w3.tradesignals.com serves a huge 
number of pages and practically every page is mostly cached. The number of 
Apache processes rarely goes over 12 or 13 at any time.. Very impressive.

http://smarty.php.net/

Donncha.

On Wednesday 18 December 2002 10:32, Ken Guest wrote:
> Not quite learning PHP,
> wondering what's the best/most used way for localising PHP websites.
> There's a lot of work/documentation on using gettext and its buddies,
> but I've also noticed that quite a few projects
> just use shiploads of variables containing the translated phrases.
>
> I know there isn't any one correct way to do this (the above is surely
> an example of this) but would value your opinions on this nonetheless.
>



More information about the Webdev mailing list