Enlaces Patrocinados:


Hoy aprenderemos cómo pasar o poner las fechas de Wordpress de inglés a español, es decir, mostrar los días y los meses en nuestro idioma.

Siempre ha sido un problema hacerlo, cuando busqué en la web no encontré ninguna solución que me lo explicase a fondo, algunas de ellas ya no servían dado que la estructura de Wordpress había cambiado (al cambiar su versión), otras sencillamente no daban mayores detalles o me eran útiles.

Lo primero que debemos hacer siempre que vayamos a realizar un cambio, en especial si se trata de un archivo de Wordpress que sea del sistema en sí, es crear un respaldo (backup). Nos dirigimos a nuestro directorio public_html/tecnologiadiaria.com/wp-includes/ y creamos una copia del archivo locale.php.

Ahora que tenemos un respaldo comenzamos a tocar el código:

  1. Abrimos nuestro archivo locale.php en modo edición y buscamos la línea 108.
  2. Allí encontraremos un código similar a éste (línea 108 a 168):
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    
    function init() {
    // The Weekdays
    $this->weekday[0] = __('Sunday');
    $this->weekday[1] = __('Monday');
    $this->weekday[2] = __('Tuesday');
    $this->weekday[3] = __('Wednesday');
    $this->weekday[4] = __('Thursday');
    $this->weekday[5] = __('Friday');
    $this->weekday[6] = __('Saturday');
     
    // The first letter of each day.  The _%day%_initial suffix is a hack to make
    // sure the day initials are unique.
    $this->weekday_initial[__('Sunday')]    = __('S_Sunday_initial');
    $this->weekday_initial[__('Monday')]    = __('M_Monday_initial');
    $this->weekday_initial[__('Tuesday')]   = __('T_Tuesday_initial');
    $this->weekday_initial[__('Wednesday')] = __('W_Wednesday_initial');
    $this->weekday_initial[__('Thursday')]  = __('T_Thursday_initial');
    $this->weekday_initial[__('Friday')]    = __('F_Friday_initial');
    $this->weekday_initial[__('Saturday')]  = __('S_Saturday_initial');
     
    foreach ($this->weekday_initial as $weekday_ => $weekday_initial_) {
    $this->weekday_initial[$weekday_] = preg_replace('/_.+_initial$/', '', $weekday_initial_);
    }
     
    // Abbreviations for each day.
    $this->weekday_abbrev[__('Sunday')]    = __('Sun');
    $this->weekday_abbrev[__('Monday')]    = __('Mon');
    $this->weekday_abbrev[__('Tuesday')]   = __('Tue');
    $this->weekday_abbrev[__('Wednesday')] = __('Wed');
    $this->weekday_abbrev[__('Thursday')]  = __('Thu');
    $this->weekday_abbrev[__('Friday')]    = __('Fri');
    $this->weekday_abbrev[__('Saturday')]  = __('Sat');
     
    // The Months
    $this->month['01'] = __('January');
    $this->month['02'] = __('February');
    $this->month['03'] = __('March');
    $this->month['04'] = __('April');
    $this->month['05'] = __('May');
    $this->month['06'] = __('June');
    $this->month['07'] = __('July');
    $this->month['08'] = __('August');
    $this->month['09'] = __('September');
    $this->month['10'] = __('October');
    $this->month['11'] = __('November');
    $this->month['12'] = __('December');
     
    // Abbreviations for each month. Uses the same hack as above to get around the
    // 'May' duplication.
    $this->month_abbrev[__('January')] = __('Jan_January_abbreviation');
    $this->month_abbrev[__('February')] = __('Feb_February_abbreviation');
    $this->month_abbrev[__('March')] = __('Mar_March_abbreviation');
    $this->month_abbrev[__('April')] = __('Apr_April_abbreviation');
    $this->month_abbrev[__('May')] = __('May_May_abbreviation');
    $this->month_abbrev[__('June')] = __('Jun_June_abbreviation');
    $this->month_abbrev[__('July')] = __('Jul_July_abbreviation');
    $this->month_abbrev[__('August')] = __('Aug_August_abbreviation');
    $this->month_abbrev[__('September')] = __('Sep_September_abbreviation');
    $this->month_abbrev[__('October')] = __('Oct_October_abbreviation');
    $this->month_abbrev[__('November')] = __('Nov_November_abbreviation');
    $this->month_abbrev[__('December')] = __('Dec_December_abbreviation');
  3. Debemos editar todas las cadenas y formato de funciones pasándolas de inglés a español. Al final nos quedaremos con esto:
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    
    function init() {
    // The Weekdays
    $this->weekday[0] = __('Domingo');
    $this->weekday[1] = __('Lunes');
    $this->weekday[2] = __('Martes');
    $this->weekday[3] = __('Miercoles');
    $this->weekday[4] = __('Jueves');
    $this->weekday[5] = __('Viernes');
    $this->weekday[6] = __('Sabado');
     
    // The first letter of each day.  The _%day%_initial suffix is a hack to make
    // sure the day initials are unique.
    $this->weekday_initial[__('Domingo')]    = __('D_Domingo_initial');
    $this->weekday_initial[__('Lunes')]    = __('L_Lunes_initial');
    $this->weekday_initial[__('Martes')]   = __('M_Martes_initial');
    $this->weekday_initial[__('Miercoles')] = __('M_Miercoles_initial');
    $this->weekday_initial[__('Jueves')]  = __('J_Jueves_initial');
    $this->weekday_initial[__('Viernes')]    = __('V_Viernes_initial');
    $this->weekday_initial[__('Sabado')]  = __('S_Sabado_initial');
     
    foreach ($this->weekday_initial as $weekday_ => $weekday_initial_) {
    $this->weekday_initial[$weekday_] = preg_replace('/_.+_initial$/', '', $weekday_initial_);
    }
     
    // Abbreviations for each day.
    $this->weekday_abbrev[__('Domingo')]    = __('Do');
    $this->weekday_abbrev[__('Lunes')]    = __('Lu');
    $this->weekday_abbrev[__('Martes')]   = __('Ma');
    $this->weekday_abbrev[__('Miercoles')] = __('Mi');
    $this->weekday_abbrev[__('Jueves')]  = __('Ju');
    $this->weekday_abbrev[__('Viernes')]    = __('Vi');
    $this->weekday_abbrev[__('Sabado')]  = __('Sa');
     
    // The Months
    $this->month['01'] = __('Enero');
    $this->month['02'] = __('Febrero');
    $this->month['03'] = __('Marzo');
    $this->month['04'] = __('Abril');
    $this->month['05'] = __('Mayo');
    $this->month['06'] = __('Junio');
    $this->month['07'] = __('Julio');
    $this->month['08'] = __('Agosto');
    $this->month['09'] = __('Septiembre');
    $this->month['10'] = __('Octubre');
    $this->month['11'] = __('Noviembre');
    $this->month['12'] = __('Diciembre');
     
    // Abbreviations for each month. Uses the same hack as above to get around the
    // 'May' duplication.
    $this->month_abbrev[__('Enero')] = __('Ene_Enero_abbreviation');
    $this->month_abbrev[__('Febrero')] = __('Feb_Febrero_abbreviation');
    $this->month_abbrev[__('Marzo')] = __('Mar_Marzo_abbreviation');
    $this->month_abbrev[__('Abril')] = __('Abr_Abril_abbreviation');
    $this->month_abbrev[__('Mayo')] = __('May_Mayo_abbreviation');
    $this->month_abbrev[__('Junio')] = __('Jun_Junio_abbreviation');
    $this->month_abbrev[__('Julio')] = __('Jul_Julio_abbreviation');
    $this->month_abbrev[__('Agosto')] = __('Ago_Agosto_abbreviation');
    $this->month_abbrev[__('Septiembre')] = __('Sep_Septiembre_abbreviation');
    $this->month_abbrev[__('Octubre')] = __('Oct_Octubre_abbreviation');
    $this->month_abbrev[__('Noviembre')] = __('Nov_Noviembre_abbreviation');
    $this->month_abbrev[__('Diciembre')] = __('Dec_Diciembre_abbreviation');
  4. Guardamos los cambios. Si desean pueden también descargar este locale.php que ya he modificado y lo reemplazan en lugar del suyo.
  5. En nuestro panel de Wordpress nos dirigimos a Settings> General, allí en la opción Time Format cambiaremos la cadena por defecto F j, Y por l, j \d\e F \d\e\l Y, donde l es la variable día, j es la variable número de día, F es la variable mes y Y es la variable año. Las variables de tipo \c donde c es una letra, son en realidad cadenas, no variables. De este modo al final tendremos algo como ésto: Viernes, 29 de Diciembre del 2008.
  6. El problema es que a veces aún haciendo este cambio no se verán reflejados los nuevos formatos de fecha en nuestro blog. Si no lo vemos en nuestra portada es porque probablemente nuestro index.php tenga su propio formato. En nuestro panel de Wordpress vamos a Design> Theme Editor, allí abrimos nuestro index.php en modo edición. Buscamos un código <?php the_time. Lo más probable es que encontremos algo como ésto:
    <?php the_time('F jS, Y') ?>
  7. En ese caso lo cambiamos por el mismo formato l, j \d\e F \d\e\l Y al que hicimos referencia en un paso anterior. Repetimos ese cambio en todos los otros bloques (categories.php, single.php, etc.) donde encontremos que no cambia el formato de fecha. Ojo, solo el formato porque al editar el locale.php nuestras fechas ya estarían en español.

Este cambio ha sido testeado en Wordpress 2.5, 2.6 y 2.6.1. Cualquier duda o comentario es bienvenido.

Publicado en: Trucos, Wordpress Comentarios (17)

Comentarios ( 17 ) en: Cómo poner las fechas de Wordpress en español
  • /grunch0 dijo:

    Yo eso lo descubrí ahi solo to rayao buscando :S ! que bien me hubiera leido leerlo de aqui.

  • Jose Perez dijo:

    Hola KnxDT

    Primero que nada felicidades, todos los cambios son para mejorar y pasando a mi duda resulta que en mi blog la fecha aparece

    4th

    ¿Como puedo hacer para que solo aparezca el 4 sin el “th”?

    Mil gracias

  • Illi.Pro dijo:

    Siempre quise saber como hacerlo, gracias por la info ;)

  • Jose Perez dijo:

    Listo, en mi theme venia jS, simplemente quite la S y el th desaparecio :D

  • Ishtar dijo:

    Muchas gracias por el artículo,viene de maravilla!

  • rm dijo:

    Checa el enlace de locale.php, ya no funciona… saludos!

  • KnxDT dijo:

    @rm: gracias por el aviso, ya lo subi.

  • carlos dijo:

    Gracias por el tutorial.
    Me ha ido estupendo.
    Pero hay una fecha que se me resiste.
    En http://dosacero.com/actividades/, aparece un Próximas actividades en el sidebar, con fechas en ingles que no se de donde salen. He buscado, creo, por todas partes, pero no las encuentro, ni en el theme, ni en locale, ni en el plugin.
    Alguna idea de donde puede salir?
    Gracias!

  • carlos dijo:

    He hecho una captura del codigo del plugin, la parte que en teoria define el formato de la fecha en Próximas actividades, y esta visible en
    http://dosacero.com/2008/08/problema-con-la-fecha/
    Gracias

  • carlos dijo:

    El plugin lo encuentras en
    http://wordpress.org/extend/plugins/calendar/
    Gracias

  • ome dijo:

    Hola

    gracias por la info

    Sabes como hacer para que entre el día y el mes aparezca la palabra “de”?

    asi quedaría por ejemplo:
    19 de noviembre

  • KnxDT dijo:

    Ome, eso lo explico justo en el punto 7, lee bien.

    Saludos.

  • actonauta dijo:

    ¡Buenísimo aporte! ya tenía rato buscando y aquí encontre muy bien la solución, ¡muchas gracias!

    ¡Saludos, éxito!

  • KnxDT dijo:

    Actonauta, hola y gracias por tomarte la molestia de comentar, un saludo.

  • Daniel dijo:

    Muy buen articulo, me ha ayudado mucho ya que he tenido que adaptar una plantilla al español totalmente.
    Un saludo.

  • KnxDT dijo:

    Que bueno que te haya servido, Daniel. Espero que regreses nuevamente por aqui :cool:

  • Guillermo dijo:

    Te pasaste! Muy bueno el tutorial, se nota que le has dedicado tiempo. Soy usuario medio de Joomla y recien estoy dando mis primeros pasos en Wordpress. Muchas gracias y saludos desde Argentina

Deja tu comentario

Comment moderation is enabled. Your comment may take some time to appear.