加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 检测Rails中的浏览器语言

发布时间:2020-12-16 19:52:03 所属栏目:百科 来源:网络整理
导读:如何检测浏览器中设置的用户语言(在RoR中)?我将有一个用户可以随时使用的选择框,但我想默认为任何他们的浏览器语言. 解决方法 Here’s the solution: 2.6 Setting the Locale from the Client Supplied Information In specific cases,it would make sense
如何检测浏览器中设置的用户语言(在RoR中)?我将有一个用户可以随时使用的选择框,但我想默认为任何他们的浏览器语言.

解决方法

Here’s the solution:

2.6 Setting the Locale from the Client Supplied Information

In specific cases,it would make sense to set the locale from client-supplied information,i.e. not from the URL. This information may come for example from the users’ preferred language (set in their browser),can be based on the users’ geographical location inferred from their IP,or users can provide it simply by choosing the locale in your application interface and saving it to their profile. This approach is more suitable for web-based applications or services,not for websites — see the box about sessions,cookies and RESTful architecture above…

One source of client supplied information would be an Accept-Language HTTP header. People may 07001 or other clients (such as curl)…

Another way of choosing the locale from client information would be to use a database for mapping the client IP to the region,such as 07002…

You can also provide users of your application with means to set (and possibly over-ride) the locale in your application interface,as well…

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读