How to automatically redirect store language

Highlighted
Tourist
11 0 5

Dear Community,

 

I'm currently making my store bilangual (Dutch/English) and I'm doing this with the Translation Lab app from Sherpas Design. They are currently still developing an automatic store language redirect and told me to use another app in the meantime.

 

I'm not a code expert or any of that kind, but can get most of the code work done with some help. So I end up here asking if there are apps or maybe even an easier way to add script to my code that will automatically redirect users to their own language page. In this case redirecting dutch users to the dutch page.

 

I'd like to hear if you guys know a solution for this function.

 

Greetings,

Ewald

0 Likes
Highlighted
Explorer
191 2 11

Hi!

 

You can potentially use Geo Redirect tool.

 

It can detect your visitors' locations by IP and auto direct them to correct website URLs based on their locations. For example, if your visitor is in Netherlands, and he goes to exampleshop.com, it will auto direct him to exampleshop.com?lang=Dutch. You can easily set up redirecting rules within a few steps. No code is necessary. The service will generate the Javascript code for you to add to your website. Shopify platform is perfectly supported.

 

For more details on how to set up auto redirect, you could look at the tutorial: https://geotargetly.com/guides/geo-redirect-quick-start-guide

 

Hope it helps.

1 Like
Highlighted
Tourist
11 0 5

In the meantime we have solved the issue with a cookie and api.

The api checks the users location and the cookie wil remember that this user has been redirected already.

We added the folowing in the beginning of our theme.js.liquid:

 

if (getCookie("language") == "") { 
  $.getJSON('https://ipapi.co/json/', function(data) {
    if(data.country_code == 'NL') {
      document.cookie = "language=NL;";
      if (!window.location.href.includes('https://vain.store/nl')){
        var url = window.location.href;
        
        
        var txt2 = url.slice(0, 19) + "nl/" + url.slice(19);
    window.location.href= txt2;
      }
  }
});
 
}
0 Likes