4
I’m having doubts on how to get the month’s value in full in Portuguese using the API of Carbon using the framework Laravel. Initially, I built this logic using PHP.
if($data->month == 1){
$mes = 'Janeiro';
}
This implies doing around 12 if’s to be able to get the value of the month in Portuguese. Assuming that the variable $data receives the value of the time of now.
$data = Carbon::now();
How could you be taking the month in full in Portuguese using only functions of API of Carbon? As shown in the example below.
$mes = $data->localeMonth;
For example, today is caught the month "July". I am also in doubt on how I can change the location to the official time of Brasilia. I believe that changing the location, can solve my problem. But it is difficult to find in the documentation of API the solution. Could you help me?
Carbon::now()->settings(['locale' => 'pt_BR', 'timezone' => 'America/Sao_Paulo',]);
changes the locale?– rray
error appears "Method Settings does not exist."
– Arthur Abitante
Which version of Laravel vc uses? and which version of Carbon?
– rray
Carbon 1.26.3 and Laravel 5.8, maybe 5.7, I’m not sure
– Arthur Abitante
In the documentation there is a part that talks about internationalizing with Cabon 1.x which basically uses the function
strftime()
that may have changed locale different from the Datetime class.– rray
where can I find this in the documentation?
– Arthur Abitante
No like is in question search for
version 1 documentation of Localization by clicking here.
there are some examples.– rray
I tried using Carbon::executeWithLocale(), Carbon::setLocale('de'), and called with $data->formatLocalized('%B'), but persists in displaying the month in English. I don’t know if you could help me, where I can get all the locations I can use for testing.
– Arthur Abitante