5
I have a website in 3 languages, EN, EN and ES.
But on some distinct machines when accessing the site by the browser is directing to page on English. This happens because of the code below which I developed to recover the browser user 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, obviously, that’s not the best way. Some users for not knowing how to install a browser, such as Chrome, end up installing it in English. Hence the code redirects the user to the site in English.
And it’s interfering with the site’s analytics. I see that Brazilian users are first accessing the site in English and a percentage of these click to enter in Portuguese. The problem is that others to see that it is in English reject the site, without at least looking for the option of changing language.
Anyway, there is some way in PHP, Laravel to search the user language in a more global way ?
Type per IP ?
Geolocation ?
Geoip ?
Yes, they are usually paid Apis... You are willing to invest?
– KaduAmaral
Bring it on. Anything I finance.
– Diego Souza
I’ve already used the project Laravel-geoip, perfectly attended to me.
– Lucio Rubens
This looks cool @Luciorubens, posted as answer.
– KaduAmaral
I’m trying to install this one from Rubens, however, for version 4 of Laravel. It’s giving a package error:
The "https://packagist.org/packages.json" file could not be downloaded: failed to open stream: Operation timed out
https://packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date
. So when I go to publish it sucks.– Diego Souza
Yeah, I tried a lot of ways here and it didn’t work out.
– Diego Souza