[wp-trac] [WordPress Trac] #23056: date_i18n() does not localize dateformat 'r'

WordPress Trac noreply at wordpress.org
Wed Dec 26 02:47:12 UTC 2012


#23056: date_i18n() does not localize dateformat 'r'
-----------------------------+--------------------------
 Reporter:  jrf              |       Type:  defect (bug)
   Status:  new              |   Priority:  normal
Milestone:  Awaiting Review  |  Component:  I18N
  Version:  trunk            |   Severity:  normal
 Keywords:  has-patch        |
-----------------------------+--------------------------
 The weekday and month strings in a date being formatted with the 'r'
 format character are not being localized.

 I've looked at the [http://core.trac.wordpress.org/browser/trunk/wp-
 includes/functions.php trunk code] and it looks like the 'r' case is not
 being considered at all in the
 [http://codex.wordpress.org/Function_Reference/date_i18n date_i18n()]
 function.


 This bug is very easy to reproduce:
 {{{
 print ( date_i18n( 'r', 972144067 ) );
 }}}

 Expected output for language Dutch:[[BR]]
 ''za, 21 okt 2000 16:01:07 +0200''

 Received output:[[BR]]
 ''Sat, 21 Oct 2000 16:01:07 +0000''



 == Potential patch: ==

 A bit of a hacky patch would go along the lines of:

 {{{
 if( !function_exists( 'patch_date_i18n' ) ) :
 add_filter( 'date_i18n', 'patch_date_i18n', 10, 4 );
 function patch_date_i18n( $formatted_date, $req_format, $timestamp, $gmt )
 {

         if( $req_format !== 'r' )
                 return $formatted_date;

         global $wp_locale;
         $datefunc = $gmt? 'gmdate' : 'date';

         $find = array (
                 $datefunc( 'M', $timestamp ),
                 $datefunc( 'D', $timestamp ),
         );
         $replace = array(
                 $wp_locale->get_month_abbrev( $wp_locale->get_month(
 $datefunc( 'm', $timestamp ) ) ),
                 $wp_locale->get_weekday_abbrev( $wp_locale->get_weekday(
 $datefunc( 'w', $timestamp ) ) ),
         );
         return str_replace( $find, $replace, $formatted_date );
 }
 endif;
 }}}

 Hope this helps. Would be great if this could be fixed.

 Smile,
 Juliette

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/23056>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list