以这个例子为例:
{{ $article->created_at->format('M') }}它返回Nov.我需要将此语言本地化为我的语言,因此输出应为Kas
It returns Nov. I need to localise this to my language, so the output should be Kas
请考虑以下事项:
{{ trans("language.{$article->created_at->format('M')}") }} app/lang/tr/language.php -> 'nov' => 'kas'这看起来像在重新发明轮子,并且在编程上非常糟糕.我确定有一些本地化标准.像这样:
This looks like reinventing the wheel and programmatically pretty terrible. I'm sure there are some localisation standards. Something like:
{{ $article->created_at->format('M')->localiseTo('tr_TR') }}实现此目标的最佳方法是什么?
What's the best way to achieve this?
推荐答案使用库作为Laravel-Date,您只需在Laravel应用配置文件中设置应用的语言,并使用其功能将日期格式化为你想要的.
Using a library as Laravel-Date you will just need to set the language of the app in the Laravel app config file and use its functions to format the date as you want.
在/app/config/app.php中设置语言
Set the language in /app/config/app.php
'locale' => 'es',我发现这个库非常有用而且干净.要使用它,您可以在自述文件库中编写类似示例的内容.我将结果保留为西班牙语.
I've found this library pretty useful and clean. To use it, you can write something like the example in the library readme file. I leave the results in spanish.
echo Date::now()->format('l j F Y H:i:s'); // domingo 28 abril 2013 21:58:16 echo Date::parse('-1 day')->diffForHumans(); // 1 día atrás这是存储库的链接:
github/jenssegers/laravel-date
要安装此库,您可以按照以下链接中详细说明的指示进行操作:
To install this library you can follow the instructions detailed in the following link:
github/jenssegers/laravel-date#installation
更多推荐
在Laravel上定位日期的最佳方法是什么?
发布评论