Skip to content

Date format 'F jS, Y' is not correct for non English languages #55

@giorgioriccardi

Description

@giorgioriccardi

Hi Morten,
I have a WP Italian site that uses Simone. The date was printed like in English st, nd or th in the 1st, 2nd or 15th
Since you smartly wrote the function pluggable if ( ! function_exists( 'simone_posted_on' ) ) : I've created a function in my child theme that overrides it:

 * Remove S from the date format for non English languages
 * [the English suffix for the day of the month st, nd or th in the 1st, 2nd or 15th]
 * http://php.net/manual/en/function.date.php
 */
function simone_posted_on() {
  $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
  if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
    $time_string .= '<time class="updated" datetime="%3$s">%4$s</time>';
  }

  $time_string = sprintf( $time_string,
    esc_attr( get_the_date( 'c' ) ),
    // esc_html( get_the_date( _x('F jS, Y', 'Public posted on date', 'simone') ) ), //original code
    esc_html( get_the_date( _x('F j, Y', 'Public posted on date', 'simone') ) ), //removed S
    esc_attr( get_the_modified_date( 'c' ) ),
    // esc_html( get_the_modified_date( _x('F jS, Y', 'Public modified on date', 'simone') ) ) //original code
    esc_html( get_the_modified_date( _x('F j, Y', 'Public modified on date', 'simone') ) ) //removed S
  );
        // Translators: Text wrapped in mobile-hide class is hidden on wider screens.
  printf( _x( '<span class="byline">Written by %1$s</span><span class="mobile-hide"> on </span><span class="posted-on">%2$s</span><span class="mobile-hide">.</span>', 'mobile-hide class is used to hide connecting elements like "on" and "." on wider screens.', 'simone' ),
    sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s">%2$s</a></span>',
      esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
      esc_html( get_the_author() )
    ),
                sprintf( '<a href="%1$s" rel="bookmark">%2$s</a>',
      esc_url( get_permalink() ),
      $time_string
    )
  );
}

This works, but unfortunately it also affects the English version. I was wondering if there is a way to implement date i18n into Simone core or child-theme function or if you can think of another solution.
Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions