We have recently upgraded our project from Rails 2.1.x to Rails 2.3.x,
and in the process also had to upgrade our Ruby-GetText.
Our config/environment.rb now refers to these GetText gems:
config.gem “gettext_activerecord”, :version => ‘>= 2.1.0’
config.gem “gettext_rails”, :version => ‘>= 2.1.0’
Things seemed to go well as everything now works fine on the
development workstations. But our production server uses a mod_proxy
cluster of Mongrel servers. It seems that now that multiple servers
are involved, Ruby-GetText (or some other component) causes confusion.
When using our language selector and switching languages, the language
is only consistent after the very first request. If you do as much as
reload the page, you may end up with parts of the page in any of the
languages you had previously chosen.
I managed to end up with a page rendering in German, English and
Spanish at the same time. Even within one partial, the language may
change – the first few columns of a table were labeled in German
while the rest was Spanish.
Our language switcher is an almost direct copy of the “default_locale”
method in the Ruby-GetText documentation:
The current code is here, in the define_locale method:
I’ve placed some logging around those bits of the method that save the
user’s language to the database, and that seems to work fine, the
language is always saved correctly and always retrieved correctly.
Before the set_locale call the GetText.locale.current might be wrong,
but after set_locale it always returns the correct locale. Yet the
page is translated in any wild way to any language.
GetText initialization seems to work, because if I replace that method
The language is always German (Switzerland) and all the spooky
language flipping stops.
Are we making any massive mistakes in our language setting? It has
worked fine since Rails 1.2.x through 2.0.x when we did our last
upgrade, but perhaps we missed something? Maybe the problem only
appears when using mod_proxy and mongrel_cluster?
Any further information or speculation would be very welcome.