微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何检测浏览器中设置的用户语言(在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…

原文地址:https://www.jb51.cc/ruby/272104.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐