如何在网络应用程序中获取用户地区/国家信息?
我的主要目的是向不同国家(语言)的人显示不同的页面。我认为它应该基于用户地区/国家,我猜可以从IP地址中获取?
例子: *对于 EN 国家的人来说,他们会看到这一点。 www.example.com
*对于日语,他们会发送至此。 www.example.com/jp
另外我看到有人说要实现这些目的,最好的方法是基于网络浏览器语言,可以从http header中获取。我不知道哪个更好,常见的方法是什么以及为什么..?
感谢您的建议!
我正在使用 Flex 和 Java。
My main purpose is to show different page to different country(language) people. I think it should be based on the user region/country, which I guess can fetch out from ip address?
example:
*For EN country people, they would see this.
www.example.com
*For Japanese, they would dispatch to this.
www.example.com/jp
Also I saw some people said to accomplish these purpose, the best way is based on the web-browser language, which can get from http header. I don't know which is better, what is the common way and why..?
Thanks for your advices!
I'am using Flex and Java.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Zolo,您可以使用 maxmind 中的 geoip 数据库之类的东西来轻松地从 IP 地址查找区域/国家/省,但它有一些缺点:
使用浏览器的 Accept: 标头通常是首选,因为在美国讲西班牙语的人可以将其语言设置设置为“es”而不是“en”,即使他们的 IP 会得到“en”。
当我过去不得不这样做时,我最终在语言选择逻辑中得到了一个有序的偏好列表,每个级别都会覆盖后续的偏好列表(如果存在):
目标当然是根据最准确反映用户偏好的内容进行选择。
Zolo, you can use something like the geoip database from maxmind to easily find region/country/province from IP addresses, but it has a few drawbacks:
Going with the browser's Accept: headers is generally preferred because a Spanish speaking person in the US can set their language settings to get 'es' instead of 'en' even if their IP would get them 'en'.
When I've had to do this in the past I ended up with an ordered preference list within the language selection logic, with each level overriding the subsequent ones if present:
The goal, of course being to base the selection on things that most accurately reflect the preferences of the user.
IP2Location 提供了几种不同的方式来获取此信息(他们拥有获取 IP 地址所需的数据)抬头)。其中包括每年 49 美元的网络服务,或者您可以以相同的价格直接从他们那里购买数据。
IP2Location offers several different ways to get this information (they have the data necessary to do an IP address lookup). This includes a web service which costs $49 per year, or you can buy the data directly from them for the same price.
确定 Web 应用程序用户选择的语言是......
一件棘手的事情!
请参阅此相关SO问题 或这个。
另一个有用的提示是使用关键字
GeoLocation
,尽管查找位置和选择的语言是两个相关但不同的问题。例如,如果地理位置表明日内瓦市中心,则法语可能是首选语言,但是德语、英语和其他几种语言几乎同样可能。
我从前面提到的SO问题中得到了以下URL:
免费IP地理定位服务
商业 IP 地理定位服务
对于语言识别(而不是位置),使用 HTTP 标头的“accept-language”非常方便且通常更准确 的价值,但这也可能会产生误导。尽管有人可能安装了日语版本的浏览器,但他/她可能更喜欢用英语阅读...
无论您为用户提供哪种语言,默认,请务必让他们轻松切换到该网站的另一个版本(如果可能,请记住此选择,以便他们返回您的网站时)
Figuring out the language of choice for a user of a web application is...
tricky business !
See this related SO Question or also this one.
Another useful hint is to use the keyword
GeoLocation
, although finding the location and the language of choice are two related but distinct problems.For example if geolocation indicates downtown Geneva, French might be the language of choice, but, German, English and several other languages are almost as probable.
I got the following URLs from the SO questions afore mentioned:
Free IP geolocation services
Commercial IP geolocation services
For language identification (rather than location), it is convenient and typically more accurate to use the HTTP Header's "accept-language" value, but that too can be misleading. Although someone may have a Japanese version of the browser installed he/she may prefer reading in English...
No matter what language you offer the users, by default, be sure to allow them to easily switch to another version of the site (and if possible, to remember this choice for when they return to your site)