Carbon locale not respected?

穿精又带淫゛_ 提交于 2020-08-19 16:57:33

问题


In my Laravel 6 app, I have Carbon::now()->locale() returning it as it should be.

As confirmation that the locale is loaded, Carbon::now()->monthName correctly outputs febbraio.

BUT Carbon::now()->format('F') and Carbon::now()->formatLocalized('%B') both return the english version February.

Why does the first function output the correct localized month while the others do not?


回答1:


Apparently, formatLocalized() is somehow deprecated or not working as intended.

From the Carbon docs:

You also may know formatLocalized() method from Carbon 1. This method still works > the same in Carbon 2 but you should better use isoFormat() instead.

Carbon::now()->isoFormat('MMMM') is working as intended and correctly returns febbraio.



来源:https://stackoverflow.com/questions/60415715/carbon-locale-not-respected

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