Laravel:在整个管理部分中以我的语言获取语言环境时间的最佳方法是什么? [英] Laravel: best way to get locale time in my language in whole admin section?

查看:60
本文介绍了Laravel:在整个管理部分中以我的语言获取语言环境时间的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Laravel 5的新手(一般来说是面向对象操作的),我正尝试从旧的过程代码切换.在整个管理部分中,我需要将语言环境时间设置为意大利语以进行查看(例如,显示日期为martedì8 dicembre 2015",而不是"2015年12月8日,星期二").

I'm new to Laravel 5 (and to OOP in general) and I'm trying to switch from my old procedural code. In the whole admin section, I need to set the locale time to Italian for viewing purposes (i.e. show dates like "martedì 8 dicembre 2015" instead of "Tuesday 8 December 2015").

到目前为止,我在config/app.php中设置了'locale' => 'it'并按如下所示更改了routes.php文件:

So far, I set 'locale' => 'it' in config/app.php and changed the routes.php file like this:

Route::group(['prefix' => 'admin'], function(){
    setlocale(LC_TIME, config('app.locale'));
    // here go all my routes
});

它有效,但是这是正确的方法吗(我的意思是,在路由文件中设置配置)?有一些更优雅的方法可以将路由与自定义配置分开吗?还是保持这样的简单性更好?

It works, but is this a correct approach (I mean, set a config in routes file)? Is there some more elegant way to keep routes separated from custom configs? Or is it better to keep simplicity like this?

更多,我仍然不知道这是否会影响日期存储到数据库中的方式(目前我仅处理记录列表,而不处理存储或更新)-当然,我的日期应存储为ISO

More, I still don't know if this can affect the way dates are stored into database (at the moment I deal only with list of records, not with store or updates) - of course my dates should be stored as ISO

非常感谢

推荐答案

不要忘记,您也可以在App/config/app.php文件中进行设置:

Don't forget that you canalso set this in your App/config/app.php file:

/*

|--------------------------------------------------------------------------
    | Application Timezone
    |--------------------------------------------------------------------------
    |
    | Here you may specify the default timezone for your application, which
    | will be used by the PHP date and date-time functions. We have gone
    | ahead and set this to a sensible default for you out of the box.
    |
    */

    'timezone' => 'Europe/Amsterdam',

这篇关于Laravel:在整个管理部分中以我的语言获取语言环境时间的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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