You just have to implement a TLD check method to you localization filter using Request::root() as second parameter for a preg_match() and then set the locale accordingly.
App::setLocale($detectedTld);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I'm busy learning laravel's localization and I was wondering is there a way to have the language change when the url looks like this
home.fr
instead of the url looking like this
home/fr/
In my routes.php
Route::group(['prefix' => '{lang?}', 'before' => 'localization'], function() {
Route::get('/', function() {
return View::make('localization_test');
});
});
my filters.php
Route::filter('localization', function() {
App::setLocale(Route::input('lang'));
});
in my lang/en/localization_test.php
return array(
'title' => 'English title',
'subtitle' => 'English subtitle',
);
in my lang/fr/localization_test.php
return array(
'title' => 'French title',
'subtitle' => 'French subtitle',
);
in my views/localization.blade.php
<h1>{{ trans('localization_test.title') }}</h1>
<h2>{{ trans('localization_test.subtitle') }}</h2>
Please or to participate in this conversation.