Localize Smarty’s {html_select_date}

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.



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:

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

Tags: ,

Did you like this post? Get monthly summary of our new tutorials, posts and tips to your inbox!

No Responses

Post Your Comment

Your email address will not be published.