Rails: How should Phusion Passenger and I18n.locale work?

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

I set the default locale to config/environment.rb

config.i18n.default_locale = 'en-GB'

The first query has no language set in I18n.locale

If I go to a page with before_filter parameter which sets I18n.locale at each subsequent visit to any controller, even if he does not have the same parameter before_filterthat I18n.locale get I18n.locale what has been established, say en-US.

In Mongrel with the same code, each request receives a locale en-GB, by default, before explicitly specified by the before_filter parameter.

Any help is appreciated if this is normal passenger behavior.

+3
source share
1 answer

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

How to hack this, in your filter you can always set the locale before setting the locale based on other parameters. Thus, it will always be reset to the last value that was set to zero at it.

Just make sure that you set the locale for each request to the user's preferred locale.

I had the same problem because I only set the locale if the input parameter told the site to change the locale. I think this is what you always need to install regardless of whether you use Phusion Passenger.

+5

Source: https://habr.com/ru/post/1703395/


All Articles