检测移动设备使用的语言并自动将网站切换到相应的语言
是否可以检测手机使用的语言来自动将我的手机网站切换到相应的语言?
举例来说, 我的网站应该以英语向在移动设备上以英语为语言的用户显示,同样,对于使用法语的用户,他们应该以法语查看该网站。
我用 jQueryMobile 开发了移动网站。它只是一个带有 HTML 和 HTML 的静态站点。一些Js计算仅此而已。
Is it possible to detect the language which is used by the mobile phone to auto switch my mobile site to that corresponding language?
Say for example,
My website should display in english to peoples who have english as their language in mobile, similarly for user who have french they should view the site in french.
I have developed the mobile site with jQueryMobile. Its just a static site with HTML & some Js calculations that's all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以这样检测用户的语言:
然后转到特定语言的页面:
You can detect the users language like this:
Then go to the language specific page:
我相信用 JS 是做不到这一点的。
其中一个选项是解析请求的“Accept-Laguage”,但要小心执行此操作,因为可能有多个设置了不同的优先级。这可以通过一些服务器端脚本以及 apache 的配置来完成。
I believe you can not do this with JS.
One of the option is to parse request's "Accept-Laguage", but do this with caution, cause there is could be several with different priority set. This can be done as with some server-side script as well as with apache's config.