Rails:Phusion Passenger和I18n.locale应该如何表现? [英] Rails: How should Phusion Passenger and I18n.locale behave?

查看:87
本文介绍了Rails:Phusion Passenger和I18n.locale应该如何表现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行在Passenger/REE上的Rails 2.2 Web应用程序

I have a Rails 2.2 web app running on Passenger / REE

我在config/environment.rb

config.i18n.default_locale = 'en-GB'

第一个请求似乎未在I18n.locale

如果我访问的页面具有before_filter,则即使以后没有任何相同的设置,每次访问任何控制器时都设置I18n.locale before_filter设置I18n.locale会得到一个已设置的I18n.locale,例如en-US.

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.

在具有相同代码的Mongrel上,每个请求都将获得默认设置en-GB的语言环境,直到由before_filter明确设置为止.

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.

推荐答案

杂种重置语言环境 自动",因为它可以处理 几乎每个请求都有不同的 线,而Phusion乘客 用相同的方式处理所有事情 线程.

Mongrel resets the locale "automatically" because it handles almost every request with a different thread, while Phusion Passenger handles everything with the same thread.

为此,在您的before过滤器中,始终可以将语言环境设置为nil,然后再根据其他参数设置语言环境.这样,它将始终将语言环境设置的最后一个值重置为nil.

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.

我遇到了同样的问题,因为我仅在输入参数告诉站点更改语言环境时才设置语言环境.我想这是无论您是否使用Phusion Passenger都必须设置的东西.

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.

这篇关于Rails:Phusion Passenger和I18n.locale应该如何表现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆