views:

411

answers:

1

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.

Thanks,

-Tim

+3  A: 

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

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.

Zack
I had the same problem, and explicitly setting i18n.locale to nil on each request solved it. Thanks!
Micah
Setting to nil didn't work for me, had to set I18n.locale = I18n.default_locale
Espen