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…

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...