I'm trying to set the same global locale of laravel which is :

config('app.locale')

与Carbon 一起工作.

似乎你可以通过以下两种方式来实现:

Carbon::setLocale('fr')

or

setlocale(LC_TIME, 'theLocale');

所以我try 使用中间件或提供者,但没有成功.

(为什么这不是laravel的默认功能?)

推荐答案

这是我的错,Carbon实际上使用的是php

setlocale();

the

Carbon::setLocale('fr')

方法仅适用于

->diffForHumans()

方法. Notice that the php setlocale() reference to the locale stored on your OS to choose one of the installed one use

locale -a

在你的控制台上

secondly, you have to use

->formatLocalized()

方法 instead of

->format()

方法

and lastly all the usefull 方法s like

->toDateString()
->toFormattedDateString()
->toTimeString()
->toDateTimeString()
->toDayDateTimeString()

没有被本地化

and lastly you have to use these parsing letters

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

Laravel相关问答推荐

子目录中具有Vue实例的Laravel不起作用

如何定制有关密码被泄露的Laravel Breeze S消息?

使用Laravel判断其他数据库中是否存在记录

Laravel 9 中使用 WHERE 子句的列的 SUM

使用两个日期之间的范围获取两列之间的记录,同时搜索过滤条件

使用枢轴插入多对多时的Laravel问题

Laravel Debugbar 中的 Laravel api routes路由

在 laravel 的集合中找到?例子

在 laravel 中更改时区

Laravel 扩展验证自定义消息

Laravel Nova - 重新排序左侧导航菜单项

如何在 Laravel 中实现数组类型路由?

Laravel 控制器构造

在 Laravel 容器中覆盖单例

Laravel 5 Mime 验证

Laravel:验证 json 对象

Laravel - 动态创建表(无需迁移)

Mac OS X 需要 Mcrypt PHP 扩展

Laravel 仓库

如何在 Laravel 中使用 SQL Server 连接?