0

I output date when post was created on Laravel blog page like that

{{ strftime('%d %b %Y', strtotime($item->created_at) )  }}

I wan to see it in format 01 Сен 2015 with russian name of month, but I have always that in english version 01 Sep 2015. I checked that locale is russian, because {{ Config::get('app.locale') }} in blade shows me ru on the page. So why I see month name in english?

I see Russian only when I put in AppServiceProvider following

    public function boot()
    {
        setlocale(LC_ALL, 'ru_RU.utf8');
    }

I tried also with Carbon {{$item->created_at->format('d M Y')}}, but again output in english. And adding string Carbon::setLocale(config('app.locale')) or Carbon::setLocale('ru') in AppServiceProvider doesn't help.

What is the problem?

schel4ok
  • 634
  • 1
  • 11
  • 33
  • I am not sure, but I think Laravel's locale config is only for working with language - [the docs don't mention anything related to PHP's locale](https://laravel.com/docs/5.7/localization). Just use the normal [PHP way - with `setlocale()`](https://stackoverflow.com/questions/46690536/laravel-app-locale-in-spanish) (with either `strftime()` or Carbon). – Don't Panic Mar 21 '20 at 12:48
  • Not really. I just tried to check php locale in blade template with `{{ locale_get_default() }}` and it shows me `ru_RU`. Of course before that I deleted setlocale from AppServiceProvider. So I am really confused. I have global locale ru_RU, but see month name in english. – schel4ok Mar 21 '20 at 14:01
  • 1
    AFAICT, [`locale_get_default`](https://www.php.net/manual/en/locale.getdefault.php) checks the OS's locale, and is not connected to PHP's `setlocale()`. From one of the comments int the `setlocale()` manual page, you can use `echo setlocale(LC_ALL, 0);` to find current locale. Did you try the accepted answer in the question I linked to? – Don't Panic Mar 21 '20 at 23:59
  • 1
    Does this answer your question? [Carbon locale not respected?](https://stackoverflow.com/questions/60415715/carbon-locale-not-respected) – NevNein Mar 22 '20 at 00:28
  • `echo setlocale(LC_ALL, 0)` gives me this `LC_COLLATE=C;LC_CTYPE=Russian_Russia.1251;LC_MONETARY=C;LC_NUMERIC=C;LC_TIME=C`. I cannot understand what means `C` everywhere except LC_CTYPE. Unfortunately I cannot use accepted answer in the question you linked, because I have not unix server. I have laragon server on windows pc and `locale-gen` or `update-locale` are not known in terminal. – schel4ok Mar 22 '20 at 18:00
  • thanks @NevNein. Your link helped me to find how to output date with Carbon. I discovered that I don't need to add `setlocale(LC_ALL, 'ru_RU.utf8')` in AppServiceProvider. It is enough just to output date with isoformat like that `$item->created_at->isoFormat('DD MMMM Y')` – schel4ok Mar 22 '20 at 18:02

0 Answers0