Reputation: 1045
i am trying to use laravel mcamara package for automatic language translation from the language files. the package supposed to be working in this way:
when i access the website for example from France and i configured french language in the package configuration file then it should be redirected to this url by default: www.example.com/fr and if i am accessing it from italy and i configured italian language then it should show: www.example.com/it below is my code for redirecting it to the exact locale but it's not working automatically:
Route::group(['prefix' => LaravelLocalization::setLocale(), 'middleware' => ['localizationRedirect', 'localeViewPath' ]], function(){ all the routes of my application is here });
Upvotes: 1
Views: 1838
Reputation: 51
at first yoy will need to detect user country by ip can use this package https://github.com/stevebauman/location , and set at boot function inside App\Providers\AppServiceProvider
public function boot()
{
$ip = request()->getClientIp();
$position = \Location::get($ip);
\LaravelLocalization::setLocale($position->countryCode);
}
and replace prefix at route group to be :
\Mcamara\LaravelLocalization\Facades\LaravelLocalization::getCurrentLocale();
route group should be :
Route::group(['prefix' => \Mcamara\LaravelLocalization\Facades\LaravelLocalization::getCurrentLocale() , 'middleware' => ['localizationRedirect', 'localeViewPath' ]], function(){ all the routes of my application is here });
Upvotes: 1