php - Laravel Carbon/Date Change Locale Doesn't Work?
Trying to serve all dates in website as another language. But It doesn't make any change.
I set 'locale' => 'tr', in config/app.php file.
My AppServiceProvider.php below:
public function boot(\Illuminate\Contracts\View\Factory $factory)
{
$factory->composer('*', 'App\Http\Views\Composers\AuthenticatedComposer');
Carbon::setLocale('tr');
}
And my resource file like:
public function toArray($request)
{
Carbon::setLocale('tr');
$user = Auth::user();
setlocale(LC_TIME, 'Turkish');
return [
"id" => $this->id,
"customer" => $this->customer,
"vehicle" => $this->vehicle,
"basket" => $this->basket,
"total" => $this->total,
"discount" => $this->discount,
"net_total" => $this->total-$this->discount,
"status" => $this->status,
"created_at" => Carbon::parse($this->created_at)->formatLocalized('%A %d %B %Y'),
"edit_allowed" => $user->power('process', 'edit'),
"delete_allowed" => $user->power('process', 'delete'),
"detail_allowed" => $user->power('process', 'detail')
];
}
I expected date to be converted Turkish. But It returns English date like: "Sunday 06 September 2020"
What's wrong with it?
Answer
Solution:
I think its supposed to be the language code like this: tr-TR
Unless its because the intl extension is not on the server. In that case try installing that "sudo apt-get install php-intl"
Source