Laravel date in full in portguês

0

I am using Laravel 5.2 and would like to bring the dates in full in Portuguese (pt_BR), however Carbon returns the textual dates only in English.

$post->created_at->formatLocalized('%B'); //"January"

In config / app.php timezone is set to 'America / Sao_Paulo' already in the 'locale' I tried pt_BR ',' pt 'and' pt_BR.UTF-8 ', not I managed to bring it in Portuguese.

I was successful in Tinker, using setlocate:

>>> setlocale(LC_ALL, 'pt_BR.UTF-8');
>>> $post = Post::find(1);
>>> $post->created_at->formatLocalized('%B');
=> "janeiro"

It's worth mentioning that I have the language pack on the server (Ubuntu Trusty x64):

$ locale -a

POSIX
C.UTF-8
C
en_**.UTF-8
pt_BR.utf8
pt_PT.utf8

My main question is what is the best way to bring Carbon dates in full in pt_BR? Where can I put the setlocale in the code? Or would it be better to use Localization?

UPDATE:

Carbon really does not support locales, because it uses the DateTime class:

  

Unfortunately the base class DateTime does not have any localization support. To begin localization support a formatLocalized ($ format) method has been added. The implementation makes a call to strftime using the current instance timestamp. If you first set the current locale with setlocale () then the string returned will be formatted in the correct locale.

As the package website itself recommends:

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

I found a good option to solve the problem using the laravel-date that extends Carbon and offers multiple languages.

    
asked by anonymous 25.01.2016 / 01:47

0 answers