Rails:Phusion Passenger 和 I18n.locale 应该如何表现?
我有一个在 Passenger / REE 上运行的 Rails 2.2 Web 应用程序
我在 config/environment.rb 中设置了默认区域设置
config.i18n.default_locale = 'en-GB'
第一个请求似乎没有在 I18n.locale 中设置区域设置
如果我访问一个带有设置 I18n.locale 的 before_filter 的页面,那么每次后续访问任何控制器时,即使它没有相同的 before_filter
设置,I18n.locale 也会获得一个 I18n.locale设置,例如,en-US
。
在具有相同代码的 Mongrel 上,每个请求都会获得默认的 en-GB
区域设置,直到由 before_filter 显式设置。
任何帮助都可以确定这是否是正常的乘客行为。
I have a Rails 2.2 web app running on Passenger / REE
I set the default locale in config/environment.rb
config.i18n.default_locale = 'en-GB'
The first request seems to have no locale set in I18n.locale
If I the visit a page with a before_filter that sets I18n.locale every subsequent visit to any controller even if it doesn't have that same before_filter
setting the I18n.locale get an I18n.locale of whatever was set, say, en-US
.
On Mongrel with the same code each request gets a locale of en-GB
, the default, until explicitly set by a before_filter.
Any help appreciated working out if this is normal Passenger behaviour.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为对此的破解,在您的 before 过滤器中,您始终可以在根据其他参数设置区域设置之前将区域设置设置为 nil。 这样,它总是会将区域设置的最后一个值重置为 nil。
只需确保您在每个请求上将区域设置设置为用户的首选区域设置即可。
我遇到了同样的问题,因为我仅在传入参数告诉站点更改区域设置时才设置区域设置。 我想无论您是否使用 Phusion Passenger,您都必须设置这一点。
As a hack to this, in your before filter, you can always set the locale to nil before setting the locale based on other parameters. This way it will always reset the last value the locale was set to back to nil.
Just insure that you're setting the locale on each request for the user's preferred locale.
I had this same problem because I was only setting the locale if an incoming parameter told the site to change the locale. I guess this is something that you always have to set regardless if you're using Phusion Passenger.