Jun 28 Localize Smarty’s {html_select_date} Written by: till |

Smarty is probably the most powerful templating system for PHP and having used it in many of my projects I assembled a couple smaller tipps and howtos which made me struggle on the way.

This is a small tipp on how to localize Smarty’s {html_select_date} function output - assuming you want the months displayed in any other language besides English which is the standard on most systems. Using German as an example, here is how to get started.



header('Content-Type:text/html;charset=iso-8859-1');
setlocale(LC_TIME, 'de_DE.ISO8859-15');
/*
create your smarty object, assign variables
to template and so on
*/
$smarty->display(’example.tpl’);
?>

As you can see, I used PHP’s header and to switch the character set. Inside setlocale, I used LC_TIME to adjust the locale settings for time and date related functions only. To change the locale for everything, use LC_ALL instead.

Here is example.tpl with Smarty’s {html_select_date}:

The date: {html_select_date}

Need evidence?

A screenshot of what we just did would be:

htmlcenter.smarty.html_sele.jpg

Notice the funky Umlaut-character (ä) in März? Well, that means you’re all set, so get localizing!

Tags: ,


Leave a Reply

KickApps
Clicky Web Analytics

community discussion