Localize your dates

Fri. 4. February 2011 Snippets Manuel
Localize your dates You go trough the trouble of building a website for multiple languages but the generated dates appear only in the server locale...
Sounds familiar? Here's a quick and easy fix, I hope you enjoy it!

First, create a new UDT for every language you wish to support.
In the example we are going to use the Dutch locale with the following name: "time_locale_nl"

 setlocale (LC_TIME, 'nl_NL.UTF8'); 

Then, paste this at the absolute top of your template before any other code:

 {time_locale_nl} 

Done, your dates will now appear in Dutch! :)

If you don't want to use different templates for all the languages you want to support, you can use something like this in your template:
(supposing your Dutch pages are located under "2" and your French pages are located under "3" in the tree structure...)

{if $friendly_position|truncate:1:"" == 2}
{time_locale_nl}
{elseif $friendly_position|truncate:1:"" == 3}
{time_locale_fr}
{/if}



Article was created by Manuel

Manuel

I'm a cmsms addict from Belgium. I had to check my forum profile but it has apparently started in 2007 :)

« Back to Articles

Comments

Categories

Archive

From Twitter

I love CMSMS

Designed and developed by idea arts. I do this! © Copyright 2010-2013

Go back to Top