Search code examples
localizationbrowser-detectioncountry

Website language: use browser locale or IP address


For a website we're about to implement automatic country/language selection, but still giving the user the choice to change it.

First of all, if the user enters the website using a domain with a country-level TLD they will be presented the correct language by default. But the question is what should the logic be if they come from generic/international TLD such as .com. Should we prefer using the country we get through their IP address or should we use their browser locale? If both, in which sequence?

As such, I was thinking of this hierarchy:

  1. Use User selection if it was changed before. If it has never been set explicitly by the user:
  2. Use hostname TLD. If it is generic (.com):
  3. Use browser locale. If no locale set or no corresponding language version is available for this locale:
  4. Use IP address. If no corresponding language version is available for the detected country:
  5. Use English.

Solution

  • As most countries have several official languages you should rely first on user preferences and then on browser locale, TLD, IP and then english as 'default' (or any major language of your main user base)