How to Pick the Right Language to Display on Your Website

Why IP geolocation is bad, and a better strategy to choose the right language for your users

Tom Feron
Tom Feron
Feb 18 · 4 min read
Photo by katie manning on Unsplash

Localisation on the web can be frustrating sometimes. Sadly, this is a problem you only encounter if you travel, you live abroad, or if you live in a multi-lingual country. That covers a lot of people but not necessarily those in charge of a web project.

It seems that the default choice made is to select a language based on the country the user is in — this, in turn, is based on their IP address. Even though this works if you’re an English-speaker living in Palo Alto, it fails miserably in a lot of other cases.

Indeed, it relies on the assumption that countries have one language and all people in said country speak that language as their primary language (or at all). This is utterly wrong. For example, in the U.S., only about 80% of the population uses English as their first language and about 13% uses Spanish instead. In Belgium, we have three official languages, namely Dutch (55% of the population), French (38%), and German (0.4%).

Not only does the default choice gives wrong answers, but it’s also overly complicated. In order to implement it, you would probably have to integrate with an external API, making your application more complex than it has to be and maybe less responsive. All of that for a suboptimal solution.


HTTP Has You Covered

Here are some examples from MDN’s documentation:

Accept-Language: de
Accept-Language: de-CH
Accept-Language: en-US,en;q=0.5

By default, browsers send the language of their graphical interface, which is quite likely to be the user’s preferred language.

It’s not a silver bullet, though, and should be used as a last resort when we have no other ways of knowing the user’s preference in this particular instance. For example, my browser is in English but I would rather see the website in French, my mother tongue, when I log in to the Belgian tax website.

So how else could we know what language to choose?


Explicit and Implicit Choices

Most of the time, traffic is coming from somewhere else rather than having the visitor type the URL in the address bar. This can give you a clue as to the language preferred by the user. If I Google something and see a result in English, I want to see the English version when I click on the link.

Some websites hide the language in a cookie or in the session. It’s better to put it straight into the URL. That way, any link already contains an implicit choice. Search results will lead to the correct version and so will links on social media or any other pages.


Fallback Strategy

It might be tempting to guess based on IP geolocation, but there is another dead-simple solution. So simple and obvious, in fact, that I don’t understand why more websites don’t use it.

Just ask.

You might not know what language the user speaks and might not be able to make a good guess, but the user knows.

After all this, there is still a possibility that you made the wrong choice. Make it easy for users to change the language. It’s not rare to see websites where it’s genuinely difficult to find the language menu. Most often it’s because the menu is written in the current language (which the user might not speak) without any visual cue. Use flags or some icon that can be understood by everyone.


In summary, a more reasonable way of picking a language goes like this:

  • If the user has made another explicit choice, use it. Try putting the language in the URL for any page that might be indexed by search engines or shared.
  • If there is an implicit choice — e.g., from the URL — use that language.
  • Otherwise, use Accept-Language.
  • If none of this works, just ask the user.

Further reading

Better Programming

Advice for programmers.

Tom Feron

Written by

Tom Feron

Software engineer with interest in functional programming and data analysis. Stay tuned on https://news.epsilonsquare.com/signup

Better Programming

Advice for programmers.

More From Medium

More from Better Programming

More from Better Programming

More from Better Programming

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade