Cómo poner las fechas de Wordpress en español

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.

Puedes leer también:


Si te gustó este artículo tal vez desees suscribirte a el canal RSS vía email completando este sencillo formulario o vía lector de feeds. Recuerda que si usas tu email debes verificar la activación de tu suscripción (si tarda mucho revisa en tu carpeta spam).

Comentarios

Recuerda leer las reglas del blog para dejar tus comentarios, de lo contrario jamás serán publicados, básicamente no mayúsculas, no lenguaje sms, no spam y no groserías ni insultos.

10 Comentarios en "Cómo poner las fechas de Wordpress en español"

  1. /grunch0 en Septiembre 4 del 2008

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


     Add rating 0  Subtract rating 0  
  2. Jose Perez en Septiembre 4 del 2008

    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


     Add rating 0  Subtract rating 0  
  3. Illi.Pro en Septiembre 4 del 2008

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


     Add rating 1  Subtract rating 0  
  4. Jose Perez en Septiembre 5 del 2008

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


     Add rating 1  Subtract rating 0  
  5. Ishtar en Septiembre 6 del 2008

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


     Add rating 0  Subtract rating 0  
  6. rm en Septiembre 22 del 2008

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


     Add rating 0  Subtract rating 0  
  7. KnxDT en Septiembre 22 del 2008

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


     Add rating 1  Subtract rating 0  
  8. carlos en Septiembre 30 del 2008

    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!


     Add rating 0  Subtract rating 0  
  9. carlos en Septiembre 30 del 2008

    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


     Add rating 0  Subtract rating 0  
  10. carlos en Octubre 1 del 2008

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


     Add rating 0  Subtract rating 0  

Deja tu comentario