A
A
AlexanderY2014-08-07 13:56:30
Laravel
AlexanderY, 2014-08-07 13:56:30

How to localize date in Laravel 4?

According to the documentation, Laravel uses Carbon when working with dates, which has a formatLocalized method . Example from documentation:

setlocale(LC_TIME, 'German');
echo $dt->formatLocalized('%A %d %B %Y');          // Donnerstag 25 Dezember 1975

I set the locale to ru_RU and try to display the day of the week:
setlocale(LC_TIME, 'ru_RU'); // это происходит в routes.php

// а это в шаблоне
// цикл и разметку я опустил, дело происходит в foreach
{{{$value->created_at->formatLocalized("%A")}}} // ожидаю увидеть "Четверг", но выводится пустая строка

The Carbon documentation says that it works with strftime when localized . I check if strftime works for me on the server:
<?php
  setlocale(LC_TIME, 'ru_RU');
  echo strftime("%A"); // корректно выводит "Четверг"
?>

How to force Carbon to display Russian date?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Grebenikov, 2014-08-07
@grealexti

I can only assume that you need to change to the desired locale in the config /app/config/app.php 'locale' => 'en',

I
Ivan Brezhnev, 2014-08-13
@vanchelo

Here is a great date localization solution for Laravel https://github.com/LaravelRUS/localized-carbon
Supports multiple languages

English (en)
Russian (ru)
Ukrainian (uk)
Dutch (nl)
Spanish (es)
Portuguese (pt)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question