Translations... where's the problem? ;-)

From: Date: Sun, 14 Apr 2002 01:53:22 +0000
Subject: Translations... where's the problem? ;-)
References: 1 2 3  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-64@lists.php.net to get a copy of this message
"Andreas Kossmeier" <andreas.kossmeier@bergfex.at> schrieb im Newsbeitrag news:3CACB389.6060009@bergfex.at... > Monte Ohrt wrote: > > Try out the block functionality in the cvs version of Smarty. You can do > > this with a custom block function: > > > > {translate lang="en"} > > blah blah blah > > {/translate} > > i don't think that this is solving his problem ;) > > but it's not a matter of the template engine. what about using a caching > layer for the database calls in your custom function? should decrease > your db calls to a minimum. > > BTW: using a block function like shown above is IMO the cleaner solution > for translating tag :) Why the heck does none never not use a modifier not to translate? (Wow, this sound negative) I love smarty's modifiers... :-)) file "lang.de.php": <?PHP global $translation; $translation = array ('yes' => 'ja', 'no' => 'nein', 'submit' => 'senden', ...and so on.... ?> In your php-app: <?PHP include ("lang.de.php"); global $translation $smarty -> assign ('dummy' , ''); //YES, IMPORTANT! ... ?> In your template: Translate static strings: {$dummy|default:"yes"|translate} Translate dynamic strings: {$yourWord|default:"empty or what ever"|translate} The plugin: function smarty_modifier_translate ($string){ global $trans; if isset ($trans[$string]){ return $trans[$string]; } else { return $string; } } That's it... ready to translate static and dynamic content. Use and add as much languages as you want without a single change to one of your templates. Add and change global translation without need to change any template for a correction of your translations and keep the translation for all templates synchronized. Because of including a separate file for each language you could also assign language dependent data like date-/timeformats, charsets and all that crap from within the included file to your templates. And at least you can combine your translations with other modifiers. Life can be so nice and easy... ;-) Regards, Norbert

« previous php.smarty.dev (#64) next »