且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

自动检测用户的首选语言和谷歌翻译

更新时间:2023-09-29 08:40:22

虽然你可以使用基于 IP 的位置检测(参见 这个答案),但它既不可靠,也不能让您更了解用户的首选语言(例如,出国旅行的用户等).

Although you can use IP-based location detection (see this answer), but it's neither reliable nor makes you wiser about user's preferred languages (e.g. users travelling abroad, etc.).

具有大量国际流量的网站使用各种参数来决定应以哪种语言呈现内容.其中一些参数:

Websites with heavy international traffic use various parameters to decide in which language the content should be presented. Some of these parameters:

  • 接受语言 详细讨论的 HTTP 标头这里.
  • window.navigator.languagewindow.navigator.userLanguage 属性的值(对于 IE)
  • 根据 CLDR 检查基于 IP 的位置检测数据,以便为您提供该地区的通用语言.
  • Accept-Language HTTP header which is discussed in detail here.
  • Values of properties window.navigator.language or window.navigator.userLanguage (for IE)
  • IP-based location detection data checked against CLDR to provide you with common languages in that territory.

MediaWiki 扩展程序 UniversalLanguageSelector 使用这些因素以及存储的用户偏好来为每个用户提供常用语言列表.请参阅 getFrequentLanguageList().

MediaWiki extension, UniversalLanguageSelector, uses these factors as well as stored user preferences to provide a list of common languages for each user. See getFrequentLanguageList().

W3C 也有一些建议.