php俄语包,英语用PHP表示俄语

我正在建立一个多语言网站,将以英语和俄语显示.除日期外,翻译方面的所有内容都运作良好.

我已经尝试过使用setlocale(LC_TIME,’ru_RU’,’russian’);然后strftime()但它只是一直返回1970年1月的unix日期.

我想要做的是从日期获取日期名称(即星期三)并显示它.通常情况下,有英文日期,我会像$this-> day = date(‘l’,strtotime($date))那样做;但是因为我试图用英语和俄语来做这件事我就这样做了这个$this-> day = strftime(“%A”,strtotime($date));

我的日期格式为“2015年10月13日”,我假设是问题的一部分,因为“十月”的俄语翻译是“Октябрь”所以我最终试图解析的最终结果是“Октябрь13 ,实际上10月13日是星期二,实际返回“星期四”的2015年.

以下是我要解析日期的所有事情:

$this->month_arr = array();

// Loop through $event_dates array created above

if(isset($_GET['lang']) && $_GET['lang'] == 'ru') {

setlocale(LC_ALL, 'ru_RU.utf8', 'rus_RUS.1251', 'rus', 'russian');

}

foreach($this->event_dates as $date => $time) {

// Create the unix timestamp to parse with PHP

$unix_date = strtotime($date);

$this->month = strftime("%B", $unix_date);

$this->day = strftime("%A", $unix_date);

$this->year = strftime("%G", $unix_date);

// Create new array with date info

$this->month_arr[$this->month][] = $this->day; // Day of week

$this->month_arr[$this->month][] = $date; // Full textual date

$this->month_arr[$this->month][] = $this->year; // 4 Digit Year

$this->month_arr[$this->month][] = $time; // Start/end time array

}

这完全解析了日期的英语表示,但其他一切似乎搞砸了.作为临时退回,我已从最终显示中删除了一周中的那一天,并且刚从初始日期字符串中删除“十月”或“Октябрь”并显示该内容,但这不是客户期望的内容.

我也试过这种格式:strftime(‘%B%e,%Y’,$unix_date);希望将strftime()格式与最初显示日期的方式相匹配将起作用,但这给了我相同的最终结果.

附:我在我的localhost MAMP服务器上运行这一切.生产/登台服务器在nginx上运行.

编辑:这是一个WordPress网站,日期是通过’Advanced Custom Fields Pro‘插件创建的.该插件不允许用户将日期保存为时间戳.我已经尝试过使用WP内置的date_i18n($format,$unix_timestamp);功能没有运气.

编辑x2:我目前正在做这样的事情:

// Russian Months

$ru_months = array( 'Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь' );

// English Months

$en_months = array( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' );

// Get date string from ACF

$date_arr = explode(" ", get_sub_field('date'));

// Get the month name

$month = $date_arr[0];

// Get the array index of the month name

$month_index = array_search($month, $en_months);

// Piece together new date string in Russian translation

$date = $ru_months[$month_index] . " " . $day . ", " . $year;

哪个适用于现在,但我也希望翻译日期名称.例如,2015年10月13日星期二,这种方法无法提供可靠的方法.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值