-
Notifications
You must be signed in to change notification settings - Fork 121
Description
We're seeing a frustrating issue where this gem works as expected most the time but sometimes in production we end up translating to the wrong language. This is on a very high volume web app where each server runs 16-32 threads of the Rails app under Unicorn.
With settings like
config.i18n.enforce_available_locales = true
config.i18n.default_locale = :en
config.i18n.fallbacks = [:en]
config.i18n.available_locales = [:en, :ja, :ko, :ru]
(note I think that fallbacks is deprecated so I plan to remove it but its been there for a long time)
99.9% of the time we will get the behavior we want but users habitually complain that they somehow get Russian despite having an accept language string like en-US,en;q=0.5 that we can see in our logs.
We previously experienced this issue more frequently before updating the gem to include this fix: 47b02be
My best idea for why this is going awry is that there is another threading issue similar to the one I linked above. Perhaps the memoization at https://github.com/iain/http_accept_language/blob/master/lib/http_accept_language/railtie.rb#L14
Does this seem reasonable?
The only deviation from a normal install of your gem that we have is we do the following in an initializer to ensure engines also get the locale set in lieu of using the HttpAcceptLanguage::AutoLocale concern.
# The locale is set this way so that ALL ActionController::Base instances (ie
# parent app + any engines) set the locale properly
ActiveSupport.on_load :action_controller do
prepend_before_filter { I18n.locale = http_accept_language.compatible_language_from(I18n.available_locales) || I18n.default_locale }
end
It almost always works (I can't reproduce the issue but it has been reported by multiple users) so threading does seem like a likely candidate.
Any ideas?