Laravel 5 Carbon全球语言环境 [英] Laravel 5 Carbon global Locale

查看:89
本文介绍了Laravel 5 Carbon全球语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将laravel设置为相同的全局语言环境:

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

config('app.locale')

与Carbon一起工作.

to work with Carbon.

似乎您可以使用以下任一方法来实现它:

It seems like you can do it by using either :

Carbon::setLocale('fr')

setlocale(LC_TIME, 'theLocale');

所以我尝试使用中间件或提供程序,但没有成功.

So I have tried using middleware or providers but was not successful.

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

(why is this not a default feature of laravel?)

推荐答案

所以这很糟糕,Carbon实际上正在使用php

So this is my bad, Carbon is actually using the php

setlocale();

the

Carbon::setLocale('fr')

方法仅适用于

->diffForHumans()

方法. 请注意,php setlocale()对存储在您的操作系统上的语言环境的引用 选择已安装的一种用途

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

locale -a

在控制台上

第二,您必须使用

->formatLocalized()

方法代替

->format()

方法

最后是所有有用的方法,例如

and lastly all the usefull methods like

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

未本地化

最后,您必须使用这些解析字母

and lastly you have to use these parsing letters

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

这篇关于Laravel 5 Carbon全球语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆