2

How can I modify month names in "Archives" in my blog? I would like to translate english month names into my mother tongue. I'm using the english version of wordpress 3.1.3

  • How do you show the month's name in the "Archives" page? – Anh Tran Jun 5 '11 at 15:33
  • May 2011, June 2011 etc. Just like e.g in this blog: blog.sqlauthority.com – jrara Jun 5 '11 at 17:57
  • No, I meant which code are you using to show month's name, not how they're shown :D – Anh Tran Jun 6 '11 at 1:15
6

if the translation is only for the archive widget, a filter function might work (to be added to functions.php of the theme):

add_filter('get_archives_link', 'translate_archive_month');

function translate_archive_month($list) {
  $patterns = array(
    '/January/', '/February/', '/March/', '/April/', '/May/', '/June/',
    '/July/', '/August/', '/September/', '/October/',  '/November/', '/December/'
  );
  $replacements = array(
    'jan', 'feb', 'mar', 'apr', 'may', 'jun', 
    'jul', 'aug', 'sep', 'oct', 'nov', 'dec'
  );    
  $list = preg_replace($patterns, $replacements, $list);
return $list; 
}
  • Great, works really well! – jrara Jun 6 '11 at 5:42
2

Depends on your theme, but some language strings may be coded in the archives.php file. Check that and also see http://codex.wordpress.org/I18n_for_WordPress_Developers

0

I believe the WordPress Multilingual plugin will do this, though I have not used it.

  • Yes, but I don't want to change the whole language of my blog, just those month names. – jrara Jun 5 '11 at 17:57
0

I made a function in 'functions.php':

function mes($month) {
switch ($month) {
case 1:
    $m_es = "ene";
    break;
case 2:
    $m_es = "feb";
    break;
case 3:
    $m_es = "mar";
    break;
case 4:
    $m_es = "abr";
    break;
case 5:
    $m_es = "may";
    break;
case 6:
    $m_es = "jun";
    break;
case 7:
    $m_es = "jul";
    break;
case 8:
    $m_es = "ago";
    break;
case 9:
    $m_es = "sep";
    break;
case 10:
    $m_es = "oct";
    break;
case 11:
    $m_es = "nov";
    break;
case 12:
    $m_es = "dic";
    break;
}
return($m_es); }

Assigning every numeric value of the months to the translation I would like to show.

Then on my 'single.php' I just gave it some format:

<?php echo get_the_date('d') . '.' . mes(get_the_date('n')) . '.' . get_the_date('y'); ?>

It's worked for me.

Saludos!

  • 1
    Just for your information: You can save yourself some code/effort and directly return the string for each case, meaning: case 1: return "ene"; case 2: return "feb"; .... That way you don't need any variable, don't need to instantiate, don't need any break;, and thus have less code. – tfrommen Apr 18 '13 at 20:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.