根据IP地址以用户的母语显示网站 [英] Display website in a user's native language based on the IP address

查看:164
本文介绍了根据IP地址以用户的母语显示网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的网站以访问者的母语打开,取决于用户登录的IP地址。



默认情况下,页面打开英语,但我希望来自法国的客户用法语阅读该网站。我已经通过 www.ipinfo.io 获取信息,但我仍然有点困惑,并希望您应该使用接受语言

如果您想要根据国家/地区自定义网站内容,请 http: //ipinfo.io 的代码看起来像这样:

  $。get(http ://ipinfo.io,function(response){
if(response.country =='US'){
// User in the USA
} else {
//用户在别处
}
},jsonp);

您可以找到完整的国家代码映射到名称,货币代码,拨号代码等等在 http://country.io/data/


I want my website to be opened in a visitor's native language as determined by the IP address where the user has logged in from.

By default the page opens in English, but I want my customers from France to read the site in French. I have gone through www.ipinfo.io for information, but I am still a bit confused and would like to know the json format.

解决方案

You should use the accept-language header that the user's browser passes to your site to determine the language, rather than the user's current country.

If you do want to customize the site content based on the country the http://ipinfo.io code you'd use would look something like this:

$.get("http://ipinfo.io", function(response) {
    if(response.country == 'US') {
        // User is in the USA
    } else {
        // User is elsewhere 
    }
}, "jsonp");

You can find a full mapping of country codes to things like names, currency codes, dialing codes and more at http://country.io/data/

这篇关于根据IP地址以用户的母语显示网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆