2015-09-13 40 views
7

我正在嘗試設置laravel同一全局區域是:Laravel 5碳全局區域

config('app.locale') 

與碳工作。

好像你可以用它做既:

Carbon::setLocale('fr') 

setlocale(LC_TIME, 'theLocale'); 

所以我一直在使用中間件或供應商嘗試過,但沒有成功。

(這是爲什麼不laravel的默認功能?)

+0

問題是/是什麼?你有沒有得到任何錯誤,或者它只是不工作? 你爲調試做了什麼?轉儲getLocale,配置等輸出? – Gummibeer

回答

6

所以這是我的壞,碳實際上是使用PHP

setlocale(); 

Carbon::setLocale('fr') 

方法只爲

->diffForHumans() 

方法。 注意到PHP的setlocale()參考存儲您的操作系統 上的語言環境來選擇安裝一個使用

locale -a 

的一個控制檯上

其次,你必須使用

->formatLocalized() 

方法代替

->format() 

種方法

,最後所有的有用的方法,如

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

沒有被本地化

,最後你必須使用這些解析字母

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

6

我在配置它AppServiceProvider。

class AppServiceProvider extends ServiceProvider 
{ 
    public function boot() 
    { 
     // Localization Carbon 

     \Carbon\Carbon::setLocale(config('app.locale')); 
    } 
}