我的Wordpress主题有一个特殊格式的日期。你可以在这里浏览网站:链接到页面
我一直在使用qTranslate,但我不知道如何改变这个特殊的日期。我想把日期改成日语和英语。代码如下:
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 -->';
}
首先,我假设您想翻译月份名称,因为这是唯一没有翻译的元素。
这里有不同的翻译方法,使用不同的方法。对你来说,你会对方法3感兴趣。
1)使用i18n与.po/。mo文件
此方法包括使用POEdit,主要用于有不同网站的情况。在这种情况下,您将不得不使用POEdit来翻译月份名称。
$arMonths = array(
1 => __('Jan'),
2 => __('Feb'),
3 => __('Mar'),
4 => __('Apr'),
// ...
);
$pretty_date_M = (isset($arMonths[date('n', $time)]) ? $arMonths[date('n', $time)] : '');
2)使用WP_LANG
这里的目标包括直接查看WordPress的当前语言是什么。同样,对于需要根据WordPress语言进行翻译的主题,它非常有用。
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)使用WP_LANG
EDIT:在这里您可以使用qtrans_getLanguage()
函数来了解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
// ...
);
}
希望对您有所帮助