Month Localization

Movable Type's present form doesn't offer any localization options for its date output. So in order to change 'January' to 'Enero' (or whatever language you prefer), you'll have to use some server-side code to fix it up.

Javi Loureiro of was in need of this solution so I wrote a quick search/replace routine to help him out. At the request of others, I'm posting here so we can all benefit. Click the MORE link for it.

This solution uses PHP, but the same technique can be used for JSP, ASP, ColdFusion, etc. (although translating this code to those forms would be an excercise for the reader). First, place the following code in your template or in a PHP file that your template includes:
function localize_month($str) {
$eng_months = array('January',
$loc_months = array('Enero',

// if you're using PHP 4.0.5 or later, this will suffice
// return str_replace($eng_months, $loc_months, $str);

// pre-PHP 4.0.5 code:
for ($i = 0; $i < 12; $i++) {
$str = str_replace($eng_months[$i], $loc_months[$i], $str);
return $str;

Now, here's how you would use this function-- place this within your Movable Type template:
<?php echo localize_month('<$MTEntryDate format="%e de %B de %Y"$> ')?>
That's it. If you happen to use this code for your site, I don't ask much-- just post a comment here to let me know the URL for your blog!


bayoe said:

How the configure for template with shtml extension?


This article was published on March 6, 2002 6:11 PM.

The article previously posted was CSS Rollovers.

The next article is CompactFlash deal.

Many more can be found on the home page or by looking through the archives.

Powered by Movable Type