Answer the question
In order to leave comments, you need to log in
How to do Laravel date localization?
There is a date display {{ $article->created_at->format('d M Y') }}
on a multilingual site, 5 languages.
Is there a way to localize the months?
Answer the question
In order to leave comments, you need to log in
Yes. I myself recently encountered this problem, it is solved trivially if the thing is hosted on Linux, but problems arise if on Windows.
First, in the place where you do it, you app()->setLocale()
need to additionally call the native php function to change the locale:
Here:
But remember that the OS on which the project is hosted must have the appropriate locales.
Further, if it $article->created_at
returns Carbon
an object, then instead format()
you need to call
. For convenience, you can put this transformation in an accessor, if necessary.
I hope you are using utf-8. And there may be problems with this if the project is hosted on Windows, as I said above. The fact is that Cyrillic locales in utf-8 are not always on board, and the only way that can be used without resorting to dancing around the OS (that is, so that the project can be deployed without pain in any environment) is to wrap the returned value in iconv(). In the same accessor, for example.
Accessor implementation example:
public function getСreatedAtAttribute($value){
return iconv('cp1251', 'utf-8', Carbon::parse($value)->formatLocalized("%d %B %Y"));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question