diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2019-07-21 18:08:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-21 18:08:02 +0200 |
commit | bd1545de5ee9655130e5357bb9cb6449520a6292 (patch) | |
tree | af0b640a9b337e291622585e2986e516170f88b7 /app/controllers/concerns | |
parent | bd87e6667975bc3b5bfaf3e1cdff97e041ed4c98 (diff) |
Change locale detection to run once per session (#8657)
Fix #6462
Diffstat (limited to 'app/controllers/concerns')
-rw-r--r-- | app/controllers/concerns/localized.rb | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/app/controllers/concerns/localized.rb b/app/controllers/concerns/localized.rb index 145549bcd..b43859d9d 100644 --- a/app/controllers/concerns/localized.rb +++ b/app/controllers/concerns/localized.rb @@ -4,16 +4,19 @@ module Localized extend ActiveSupport::Concern included do - before_action :set_locale + around_action :set_locale end private def set_locale - I18n.locale = default_locale - I18n.locale = current_user.locale if user_signed_in? - rescue I18n::InvalidLocale - I18n.locale = default_locale + locale = current_user.locale if respond_to?(:user_signed_in?) && user_signed_in? + locale ||= session[:locale] ||= default_locale + locale = default_locale unless I18n.available_locales.include?(locale.to_sym) + + I18n.with_locale(locale) do + yield + end end def default_locale |