在 Rails 3 中运行时更改区域设置
我正在开发一个 Rails 3 应用程序,它在我的区域设置文件夹中有不同的语言。这些文件是 en.yml、pu.yml、sp.yml。所有语言都必须转换为各种格式,我需要帮助让用户选择他们选择的任何语言,并使用类似
<%= link_to "English language", ...%> <%= link_to "spanish", ...%>
当用户选择语言时,该语言被设置为用户的首选语言,以便用户没有每次登录后继续选择语言。
I am working on a rails 3 app which has different languages in my locales folder. The files are en.yml, pu.yml, sp.yml. All languages have to be converted to their various format and I need help in making users chose any language of their choice with a link like
<%= link_to "English language", ...%> <%= link_to "spanish", ...%>
When a user choses a language, the language is set as the user's preferred language so that the user does not have to keep selecting a language after each login.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需将
locale
字符串属性添加到您的User
模型中,并在您的application_controller.rb
中创建一个before_filter
,如下所示:更多信息请访问 Rails 国际化 (I18n) API!
Just add a
locale
string attribute to yourUser
model, and make abefore_filter
in yourapplication_controller.rb
like so:More infos at Rails Internationalization (I18n) API!
添加到 ream88 的答案:
在 LocaleController (或任何其他控制器)中
Adding to ream88's answer:
In the LocaleController (or any other controller)