Multilingual Date for a WordPress Theme

My WordPress theme has the date in a special format. You can view the website here:
Link to Page

I’ve been using qTranslate, but I’m not sure how to change this special date. I’d like to make the date Japanese as well as English. Here is the coding:

if (have_posts())
while (have_posts()):
    the_post();
    global $post;
    $results        = $wp_query->post_count;
    $data_event     = get_post_meta($post->ID, 'event_date_interval', true);
    $time           = strtotime($data_event);
    $pretty_date_yy = date('Y', $time);
    $pretty_date_M  = date('M', $time);
    $pretty_date_d  = date('d', $time);
    $image_id       = get_post_thumbnail_id();
    $cover          = wp_get_attachment_image_src($image_id, 'event-cover-arc');
    $image_id       = get_post_thumbnail_id();
    $event_location = get_post_meta($post->ID, "event_location", true);
    $event_venue    = get_post_meta($post->ID, "event_venue", true);
    $tstart         = get_post_meta($post->ID, 'event_tstart', true);
    $tend           = get_post_meta($post->ID, 'event_tend', true);
    $event_ticket   = get_post_meta($post->ID, "event_ticket", true);
    $event_out      = get_post_meta($post->ID, "event_out", true);
    $event_cancel   = get_post_meta($post->ID, "event_cancel", true);
    $event_zoom     = get_post_meta($post->ID, "event_zoom", true);
    $coordinated    = get_post_meta($post->ID, "event_coordinated", true);
    $club           = get_post_meta($post->ID, "event_venue", true);
    $event_allday   = get_post_meta($post->ID, "event_allday", true, true);
    echo '
<div class="event-cover">';
    if ($data_event != null) {
        echo '        
  <div class="event-single-data">
    <div class="event-single-day">' . $pretty_date_d . '</div>
    <div class="event-single-month">' . $pretty_date_M . '</div>
    <div class="event-single-year">' . $pretty_date_yy . '</div>
  </div>            
</div><!-- end .event-cover -->';
    }

Related posts

Leave a Reply

1 comment

  1. First of all, I will assume you want to translate the month name, since this is the only elements not translated.

    Here are differents ways to translate, using various methods In your case, you will be interested by method 3.

    1) using i18n with .po/.mo files

    This method consists to use POEdit and is mainly used when there are differents websites.
    In that case you will have to use a POEdit to translate the months names.

    $arMonths = array(
      1 => __('Jan'),
      2 => __('Feb'),
      3 => __('Mar'),
      4 => __('Apr'),
      // ...
      );
    
    $pretty_date_M = (isset($arMonths[date('n', $time)]) ? $arMonths[date('n', $time)] : '');
    

    2) using WP_LANG

    Here the goal consists to see directly what is the current language of WordPress. Once again, it’s mostly useful for a theme that require to be translated depending on the WordPress language.

    if ( WP_LANG=='ja_JP' ) {
      // default language is japanese ?
      $arMonths = array(
        1 => '?', // january in japanese
        2 => '?', // february in japanese
        3 => '?', // march in japanese
        4 => '?', // april in japanese
        // ...
        );
    } else {
      // otherwise english (?)
      $arMonths = array(
        1 => __('Jan'),
        2 => __('Feb'),
        3 => __('Mar'),
        4 => __('Apr'),
        // ...
        );
    }
    
    $pretty_date_M = (isset($arMonths[date('n', $time)]) ? $arMonths[date('n', $time)] : '');
    

    3) using WP_LANG

    EDIT : here you can use qtrans_getLanguage() functions to know what is the current language of qTranslate.

    if ( qtrans_getLanguage()=='en' ) {
      // current language code is 'en' (English)
      $arMonths = array(
        1 => __('Jan'),
        2 => __('Feb'),
        3 => __('Mar'),
        4 => __('Apr'),
        // ...
        );
    } else {
      // otherwise, I assume it's in japonese
      $arMonths = array(
        1 => '?', // january in japanese
        2 => '?', // february in japanese
        3 => '?', // march in japanese
        4 => '?', // april in japanese
        // ...
        );
    }
    

    Hope that help