Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

config('app.locale')

to work with Carbon.

It seems like you can do it by using either :

Carbon::setLocale('fr')

or

setlocale(LC_TIME, 'theLocale');

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
484 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

setlocale();

the

Carbon::setLocale('fr')

method is only for the

->diffForHumans()

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

locale -a

on your console

secondly, you have to use

->formatLocalized()

method instead of

->format()

method

and lastly all the usefull methods like

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

are not being localized

and lastly you have to use these parsing letters

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...