如何在网络应用程序中获取用户地区/国家信息?

发布于 2024-08-19 17:45:10 字数 284 浏览 7 评论 0原文

我的主要目的是向不同国家(语言)的人显示不同的页面。我认为它应该基于用户地区/国家,我猜可以从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

惜醉颜 2024-08-26 17:45:10

Zolo,您可以使用 maxmind 中的 geoip 数据库之类的东西来轻松地从 IP 地址查找区域/国家/省,但它有一些缺点:

  • VPN 和缓存可能会产生错误值
  • 用户无法轻松覆盖它。

使用浏览器的 Accept: 标头通常是首选,因为在美国讲西班牙语的人可以将其语言设置设置为“es”而不是“en”,即使他们的 IP 会得到“en”。

当我过去不得不这样做时,我最终在语言选择逻辑中得到了一个有序的偏好列表,每个级别都会覆盖后续的偏好列表(如果存在):

  1. 通过滑动站点上的标志图标来表达用户偏好,存储在会话中或cookie
  2. 域的 TLD,其中 .com 没有任何意义(例如:mycompany.jp 为您提供日语网站,但 mycomany.com 是“否决”,并通过
  3. 接受标头的浏览器语言设置
  4. GeoIP 最佳猜测
  5. 回退到英语

目标当然是根据最准确反映用户偏好的内容进行选择。

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:

  • VPNs and caches can yield false values
  • User's can't easily override it.

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:

  1. Expressed user preference by slicking a flag icon on site, stored in session or cookie
  2. The TLD of the domain, with .com signifying nothing (ex: mycompany.jp gets you Japanese site, but mycomany.com is a "no vote" and passes through to the next level
  3. Browser language setting from the accept header
  4. GeoIP best guess
  5. Fallback to English

The goal, of course being to base the selection on things that most accurately reflect the preferences of the user.

注定孤独终老 2024-08-26 17:45:10

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.

女中豪杰 2024-08-26 17:45:10

确定 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文