admin管理员组文章数量:1327684
I need to implement an autodetect feature for a simple, plain html website I am working on. It has two languages and the client wants it to automatically select the language. This could be done either via the browser's language or geolocalization, both options are good.
Can someone point me to a good script or solution to do this? ive been searching for a while and cant seem to find anything...
Thank you
I need to implement an autodetect feature for a simple, plain html website I am working on. It has two languages and the client wants it to automatically select the language. This could be done either via the browser's language or geolocalization, both options are good.
Can someone point me to a good script or solution to do this? ive been searching for a while and cant seem to find anything...
Thank you
Share Improve this question asked Mar 10, 2010 at 9:24 agente_secretoagente_secreto 8,07916 gold badges60 silver badges83 bronze badges 1- Don't use Geolocalization, never! 1) You travel to another country, that does not makes you speak that language. 2) In countries with multiple languages (India, Canada, Switzerland...), this is not going to work. 3) VPNs 4) Complex tracking and data-protection issues. – Adrian Maire Commented Jan 28 at 14:17
4 Answers
Reset to default 4Use the Accept-Language HTTP header.
You could use the UserAgent of the Browser.
I wouldn't use geo-localization...I'm in Austria but I prefer websites in english, that's why I changed my UserAgent to resemble that, and most websites stick to it.
The Accept-Language HTTP header is usually the best way, but is only available on the server. Since your using a plain (I read static) html page and JavaScript, you'll need a different approach.
Different browsers expose language information in different ways:
document.navigator.language; // firefox
document.navigator.browserLanguage; // IE
I'm not sure what other browsers do. I think the values will be things like "en" or "en-us", so you should experiment. For the browsers you target, set the language setting to the ones your interested in, and see what the above values pop out of the above expressions.
in javascript, language info is stored in the global navigator object (navigator.language in FF and navigator.browserLanguage/systemLanguage in MSIE).
本文标签: javascriptMost effective way to auto detectselect language in a websiteStack Overflow
版权声明:本文标题:javascript - Most effective way to auto detectselect language in a website? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742215328a2434461.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论