Reputation: 1182
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.
Upvotes: 8
Views: 33366
Reputation: 1
I ran into a similar problem. I just added missing locale on my system. For Ubuntu, if you need add russian locale type below:
sudo locale-gen ru_RU
sudo locale-gen ru_RU.UTF-8
sudo update-locale
don't forget restart your php-fpm after it
Upvotes: 0
Reputation: 141
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
Upvotes: 4
Reputation: 1182
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');
Upvotes: 15
Reputation: 109595
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.
Upvotes: 2