Skip to main content

Auto lang. switch according to visitors geolocation

Hello in different languages of the world

Assuming, that we already have a multilingual  Drupal 8 site, we can simply place the language switcher somewhere in the site’s header, and thats it. But if we want to be a little bit nicer to our visitors, we can do it instead of them, and do a redirect automatically, by their ip address. So why not.

First of all, we need a module called IP Language Negotiation. It requires two more modules:
The first is IP-based Determination of a Visitor's Country and the second one is Global Redirect.

After we installed the modules, we can go to the language settings (admin/config/regional/language) and config the selection under Detection and selection tab.
We can see, that we have got a new option – IP address. Lets configure it!

Screenshot of the language detection methods

Under the ip address configuration (admin/config/regional/language/detection/ip) we can see the list of countries and the languages installed to our site. We have nothing more to do than to choose the country – language pairs for example Spanish for Spain.

Screenshot of the language selection according to the visitors country

If we finished configuring it, we must enable the IP address in the Detection and selection settings, and move it up to the top, to give it a higher priority.

After we are done with it, the IP-based Determination of a Visitor's Country gets the ip and identify it’s location. The Global Redirect is just redirects it to the language what we have set for it, but as a fall-back, the default language is used.