I'm editing a script to customize the day into Indonesian, how do I translate it in carbon getdays?
this is the script contained in app/Support/Date.php
public static function dayFromInt($num)
{
return Arr::get(Carbon::getDays(), $num);
}
CodePudding user response:
Use
Carbon::setlocale('id-ID');
CodePudding user response:
Please set the timezone in config/app.php
, like
'timezone' => 'Asia/Kolkata'
And then use laravel illuminate carbon instead of Carbon\Carbon
use Illuminate\Support\Carbon;
Then laravel automatically translate carbon values into Kolkata timezone in everywhere you use carbon
CodePudding user response:
Well, I couldn't make Carbon::getDates() work with different locale, but it just returns an array of the days of the week, so you can change the function like:
public static function dayFromInt($num)
{
//change with values in your language
$weekdays = [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday'
];
return Arr::get($weekdays, $num);
}
CodePudding user response:
public static function dayFromInt($num)
{
return Carbon::parse('Sunday')
->addDays($num)
->locale('id_ID')
->dayName;
}