Re: [SMARTY] Internationalization

From: Date: Tue, 30 Jul 2002 19:50:16 +0000
Subject: Re: [SMARTY] Internationalization
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-5515@lists.php.net to get a copy of this message
On 30/07/02 16:19, "Garland foster" <garland_foster@salutia.com> wrote: > Hi, > > I want to discuss which is the best approach for internationalization using > Smarty, > I thought about using config files and loading the specified config section > for each > page, then displaying the strings as {#string_name#}. > > The main problem with this approach are error messages, error messages are > generated at the logic level of the application in contrast with application > strings > that are generated at the presentation level (templates). If I want to go to > the > "error template" displaying something like: > "the username $user doesn't exist" how can I do it using config files? > > Other ideas or approaches? > > Thanks, > Garland > > I think that this is not the purpose of config files... U should use a database to do that, because it's build FOR THAT... :) Having huge arrays in config files containing all the translations is not a good idea to me, because php has to load in memory the all array for each translation.... U can make a php function to retrieve translation from your database (taking $lang and $id in argument per exemple... $lang is the language and $id is the id of the line u want to translate...) Lets call this function 'translate' After that U just have to make a Smarty Plugin to achieve the translation inside the templates... function smarty_function_translator($params, &$this) { extract($params); $translate = new translate; $this->_compile_template("evaluated template", $translate->translate($id,$lang), $source); eval('?>' . $source); } With this piece of code, if u store something like 'my name is {$NAME} and i live in {$CITY}' in the database, it will be translate perfectly... The bad point of this method is that it will quickly make alot of calls to the DB... But i think that a DB is build to achieve such tasks and NOT PHP!

« previous php.smarty.general (#5515) next »