In this example we will be using PHP carbon library with PHP functions to display Laravel localized time based on language selected in Laravel website. We will converting time for eight languages, you can extend for languages you want to show time for. All these examples are inspired from Scratch Coding Laravel Coding
Languages
First of all we will get selected language for a multi-Lang laravel website and store it in a variable.
$locale = app::getLocale();
Now based on selected language, We will use switch case to find selected language and display time
switch ($locale) {
case 'en':
$locale_str = "en_US.UTF-8";
$locale_lctime = "en_US";
break;
case 'ar':
$locale_str = "ar_AE.utf8";
$locale_lctime = "ar_AE";
break;
case 'de':
$locale_str = "de_DE.UTF-8";
$locale_lctime = "de_DE";
break;
case 'es':
$locale_str = "es_ES.UTF-8";
$locale_lctime = "es_ES";
break;
case 'fr':
$locale_str = "fr_FR.UTF-8";
$locale_lctime = "fr_FR";
break;
case 'in':
$locale_str = "hi_IN.UTF-8";
$locale_lctime = "hi_IN";
break;
case 'pt':
$locale_str = "pt_PT.UTF-8";
$locale_lctime = "pt_PT";
break;
case 'ru':
$locale_str = "ru_RU.UTF-8";
$locale_lctime = "ru_RU";
break;
case 'it':
$locale_str = "it_IT.UTF-8";
$locale_lctime = "it_IT";
break;
default:
$locale_str = "en_US.UTF-8";
$locale_lctime = "en_US";
}
setlocale(LC_ALL, $locale_str);
$startDate = strftime("%A, %F", strtotime(\Carbon\Carbon::now()->subDays(6)->format('Y-m-d')));
$endDate = strftime("%A, %F", strtotime(\Carbon\Carbon::now()->format('Y-m-d')));
Now we time in local language selected in laravel, we will display it in blade.
{{ $startDate }} to {{ $endDate }}
A list of the best spas in Dubai that will relax your body and mind…
Canada is a majestically beautiful country full of natural wonders and is also home to…
Here is a list of the Best USA Makeup Brands in 2023, that are safe…
Here is a list of the Best Australian Makeup Brands in 2023, that are safe…
Content creators always try hard to make their content reach a large number of followers…
Truck companies are constantly searching for people to fulfill their logistics, transportation, and supply chain…