Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setlocale(LC_ALL, 'it_IT'); set, but still dates in english

I have this code which through json_decode retrieves my latest tweets, their date, etc.

<?php setlocale(LC_ALL, 'it_IT'); ?>
<?php include("twitter_auth.php");
echo "<ul style='color:#6E6E6E'>";
foreach ($twitter_data as $tweet)
{
    if (!empty($tweet)) {
        $text = $tweet->text;
        $text_in_tooltip = str_replace('"', '', $text); // replace " to avoid conflicts with title="" opening tags
        $id = $tweet->id;
        $time = strftime('%d %B', strtotime($tweet->created_at));
        $username = $tweet->user->name;
    }
    echo '<li><span title="'; echo $text_in_tooltip; echo '">'; echo $text . "</span><br>
        <a href=\"http://twitter.com/"; echo $username ; echo '/status/'; echo $id ; echo '"><small>'; echo $time; echo '</small></a> - 
        <a href="http://twitter.com/intent/tweet?in_reply_to='; echo $id; echo '"><small>rispondi</small></a> - 
        <a href="http://twitter.com/intent/retweet?tweet_id='; echo $id; echo '"><small>retweet</small></a> - 
        <a href="http://twitter.com/intent/favorite?tweet_id='; echo $id; echo '"><small>preferito</small></a></li>';
}

echo '</ul>';
?>

Problem is that $time outputs something like "03 February" even though there is a setlocale(LC_ALL, 'it_IT');. What's the error? How can I have dates output in italian? System: PHP 5.4.11 and nginx (on Ubuntu Server).

EDIT: I also ran dpkg-reconfigure locales:

Generating locales...
  en_US.UTF-8... up-to-date
  it_IT.UTF-8... up-to-date
Generation complete.
like image 757
MultiformeIngegno Avatar asked Feb 06 '13 19:02

MultiformeIngegno


People also ask

What is set locale?

The setlocale() function is used to set or query the program's current locale. If locale is not NULL, the program's current locale is modified according to the arguments. The argument category determines which parts of the program's current locale should be modified.

How does Setlocale work?

The setlocale() function of the PHP programming language usually works by returning the locale information with the help of the two mandatory parameters. It just returns the locale information/info. The return value of the setlocale() function is the current locale settings but on failure, FALSE will be returned.

What is locale PHP?

A "Locale" is an identifier used to get language, culture, or regionally-specific behavior from an API. PHP locales are organized and identified the same way that the CLDR locales used by ICU (and many vendors of Unix-like operating systems, the Mac, Java, and so forth) use.


1 Answers

Silly as it may sound I solved changing the line to:

<?php setlocale(LC_ALL, 'it_IT.UTF-8'); ?> 
like image 198
MultiformeIngegno Avatar answered Nov 08 '22 22:11

MultiformeIngegno