【发布时间】:2021-04-03 01:53:06
【问题描述】:
大家好,我需要一些关于翻译碳值日期、时间等方面的帮助......,
例如使用{{ date('M d, Y',strtotime($something->created at)) }}
那么它将显示为-> Apr 03, 2021
我的问题是我们如何将“Apr”翻译成其他语言,在过去 3 天里,我在这个案例上花了超过 3 天的时间寻找可能的方法,但没有运气:(,如果你能帮助我和其他需要这个解决方案的人
我也尝试过不止一种方法,比如在providers.php上写这个
$app = $this->app && method_exists($this->app, 'getLocale') ? $this->app : app('translator');
$locale = $app->getLocale();
Carbon::setLocale($locale);
CarbonImmutable::setLocale($locale);
CarbonPeriod::setLocale($locale);
CarbonInterval::setLocale($locale);
【问题讨论】:
-
你不能使用 date() 来翻译,你应该用 Carbon 对象格式化它,例如$something->created_at->locale('ab_cd')->format('dddd MMMM YYYY')
-
试试
now()->locale($locale)->translatedFormat('M d, Y');。 carbon.nesbot.com/docs/#api-localization
标签: laravel