I have a website in 3 languages, EN , EN and EN .
But on some separate machines when accessing the site by the browser is directing to page in English . This happens because of the code below that I developed to retrieve the user's browser language.
App::before(function($request){
$l = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
$l = ($l == 'pt') ? null : $l;
if(!is_null($l)){
$l = in_array($l, Config::get('app.languages')) ? $l : 'en';
}
});
It turns out that, obviously, this is not the best way. Some users who do not know how to install a browser, like Chrome for example, end up installing it in English. Hence the code redirects the user to the site in English.
And this is interfering with site analytics. By the graph I see that Brazilian users are accessing the site in English first and a percentage of these click to enter in Portuguese. The problem is that others because they see that it is in English reject the site, without even looking for the option of the language exchange.
Anyway, is there any way in PHP, Laravel to fetch the user language in a more global way?
Type per IP?
Geolocation?
GeoIP?