I am trying to use Russian language with setlocale:
setlocale(LC_TIME,"ru_RUS.utf8");
echo strftime("%A, %B %d", time());
Output is : Thursday, August 29
Expected is : четверг, Август 29
Any help would be highly appreciated.
Found it! if you are using Linux hosting then try:
setlocale(LC_ALL, 'ru_RU.UTF-8');
will works fine. In case you are using windows hosting then try:
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
setlocale(LC_ALL, 'russian');
For the Russian locale and UTF-8 it is possible to use such code. Work in Widows and Unix.
header('Content-type: text/html; charset=utf-8');
$locale_time = setlocale (LC_TIME, 'ru_RU.UTF-8', 'Rus');
function strf_time($format, $timestamp, $locale)
{
$date_str = strftime($format, $timestamp);
if (strpos($locale, '1251') !== false)
{
return iconv('cp1251', 'utf-8', $date_str);
}
else
{
return $date_str;
}
}
echo strf_time("%A, %B %d", time(), $locale_time);
Result:
вторник, Октябрь 13
var_dump(setlocale(LC_ALL, 'ru_RU.utf8'));
The function setlocale returns the result of the system call. I think it should be RU, not Ru.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With