Reputation: 108
I want to create a webpage in 3 languages. I want is that when user click from a specific location, the content of the website changes accordingly. e.g. This means that IP from German will lead to page in German and so on. My website in Wordpress. Please Help.
I tried Gtranslate Plugin.
Its working fine when choose from dropdown. But I want website translate on page load in particular language.
Using Following I get IP address and location of visitor
$.getJSON('https://ipapi.co/json/', function(data) {
console.log(data.country_code);
if(data.country_code=='IN'){
$(".gt_selector").val('en|hi');
$("a[title='Hindi']").trigger('click');//not working
}
if(data.country_code=='MY'){
$(".gt_selector").val('en|ms');
}
});
Upvotes: 0
Views: 116
Reputation: 51
IP-based language detection assumes that the user's location correlates with their preferred language, and it's not correct behaviour. For example, a Hindi-speaking person traveling in Malaysia may prefer to browse websites in Hindi. There's also a whole topic of Proxy Servers and VPNs that can can mask user's IP address.
I would suggest using accepted languages of the browser instead of IP.
In PHP you can do it easily using $_SERVER["HTTP_ACCEPT_LANGUAGE"]
.
See Using the PHP HTTP_ACCEPT_LANGUAGE server variable .
Upvotes: 2