How to set language for Carbon?

删除回忆录丶 提交于 2019-12-01 20:15:08

try using PHP function setlocale also check if your hosting allows and gives you the locales you want.

 setlocale(LC_TIME, 'es_ES');
 Carbon::setLocale('es');
 $archive_current_year = Articles::whereBetween('created_at', [
 ....

Carbon is actually using the php setlocale();. The Carbon::setLocale('es') method is only for localized Carbon methods like ->diffForHumans() method.

As explained here, notice that the php setlocale() reference to the locale stored on your OS. To choose one of the installed one, type locale -a on your console. Secondly, you will have to use ->formatLocalized() method instead of ->format() in order to use the format on the desired locale which can be found at the following link.

http://php.net/manual/en/function.strftime.php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!