Re: [SMARTY] Internationalization

From: Date: Mon, 27 Jan 2003 22:47:34 +0000
Subject: Re: [SMARTY] Internationalization
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-7355@lists.php.net to get a copy of this message
Greetings Andrew! It is possible to create some really nice internationalization with Smarty. I was playing around with it some months ago and it ended up in something like this: First of all, I have dictionaries containing the strings for the different languages, I chose to store these in XML format. Anyway, how you store it is not really important, because that information is only retrieved very seldom (when the templates are recompiled). Anyway, my templates looked something like this: ##userName##: <input type="text"....> ##password##: <input type="text"...> I had a constant in my scripts, _LANG_, which was the language specified (en, sv etc). $smarty->compile_id = _LANG_ I implemented a prefilter that replaced the above tags to the strings from the language the user had specified: function smarty_prefilter_translate($tpl_source) { global $_strings; $dict = new Dictionary(_LANG_); $_strings = $dict->getStrings(); return preg_replace_callback('/#[#%](.+?)[#|%]#/', '_translate', $tpl_source); } function _translate($key) { global $_strings; $value = $_strings[$key[1]]; if($value) return $_strings[$key[1]]; else return $key[0]; } By using a compile id, I got the following templates_c/-structure: templates_c/en/ templates_c/sv/ templates_c/ru/ So you get a compiled version of each of your languages. I also had a prefilter that scanned a template for tags and then created a form so a (admin) user could add strings to the different dictionaries online, without having to mess with the XML-files. I hope this helped some. /Nichlas > I was reading a thread about internationalization that took place in July > and august of 2002, I am trying to design a large scale web application > using multiple languages. I don't want to have a template for each > language, because that can get very messy considering I have two sets of > templates already for 2 different look and feels. > > Has anyone accomplished this feat? I was wondering if anyone has any ideas > on an implementation of gettext for smarty? > For now I am planning to create a large associative array, but it would be > nice to follow some sort of standard. Has anyone tried running gettext on > tpl files? > > I tried looking into the binary cloud information, but I couldn't find too > much in the documentation. Maybe I'll download it and take a look at the > code.

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