Search code examples
phplaravelphp-carbon

Carbon setLocale not working Laravel


Ive read several stackoverflows about set locale. I tested locale -a in the terminal to see if my locale was in there, and it was. The following rule of code is added in the appServiceProvider:

public function boot()
{
    Carbon::setLocale($this->app->getLocale());
}

The $this->app->getLocale() returns "nl"

Anyone know why Carbon still shows Sunday instead of Zondag for example?


Solution

  • You might want to use setLocale(LC_TIME, $this->app->getLocale()) somewhere at the start of your application.

    Then if you wish to have the localized date format with local names use the formatLocalized function

    Carbon::now()->formatLocalized('%d %B %Y');
    

    See http://php.net/manual/en/function.strftime.php for parameter for formatting