How to detect user's language: via IP location or browser?
#1
I want to personalize the content of the website to its visitors based on what language they speak. I see two ways to do this:

1) locate a visitor's IP. My logic is: if visitors access from IP in Paris, they speak French and would like to read content in French. All I need is to use a geolocation API that is easy to find, like this one so far https://www.abstractapi.com/ip-geolocation-api.

However, if I have visitors from Canada, they can speak English or French or both. How to know which language to use in that case?

So, I'm thinking of option #2.

2) rely on a visitor's browser accept-language header. But I'm wondering how accurate is it? What can be the drawbacks of this approach?

Let me know please how you tailor the language of the content to website visitors.

Thanks!
Reply
#2
I think that IP is a bad choice, because of:
- as you said, some countries have multiple official language (Canada, Belgium, Swiss, ...)
- more and more users use VPN
- you'll be quickly limited with geoip providers quotas unless you pay
- it could use too much resources from your server
- probably other negative things Smile

I think the accept-language works well, I was used to use it when working in web-agency. But you must let the ability to user to change his language.
[MyBB 1.8 mods] - Offer me a coffee
Do not ask me help through PM
Reply
#3
I'd agree with the above - using what the browser sends you will be more reliable than trying to look up the location by IP. I used to use this to select the initial language but then still give the option to change it. IP lookups can often be a bit slow to do too so adds additional page load latency for users.
MyReactions - All Plugins

Can you still feel the butterflies?

Free never tasted like pudding.
Reply
#4
Thanks for sharing your thoughts! Will proceed with the accept-language and allow users to choose the language.
Reply
#5
Your better choice should be detecting browser language, thats the language the user is probably using as per his own choice. This detection is js based:
<script type="text/javascript">
var Lang = navigator.language || navigator.userLanguage; 
</script>


Or you can attempt to detect best available locale based on HTTP "Accept-Language" header
$lang = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
Reply
#6
The second option is better than the first one.
Reply
#7
Hi Karmadele, for your second option there's a plugin here you might find useful :

Browser-based Language :
https://community.mybb.com/mods.php?action=view&pid=636
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)