about summary refs log tree commit diff
path: root/app/controllers/application_controller.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-11-16 17:51:02 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-11-16 17:56:31 +0100
commit2c766bd4b4c6dcf8e7c9a6dd9421edca0de57aba (patch)
treed84f472de5ff84502928fec8582be492c45a6faf /app/controllers/application_controller.rb
parent01e43c3e5799b575a70798056945365ddf51f3ad (diff)
Add user locale setting
Diffstat (limited to 'app/controllers/application_controller.rb')
-rw-r--r--app/controllers/application_controller.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index c7a99b22f..f9aeb127a 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -13,6 +13,7 @@ class ApplicationController < ActionController::Base
   rescue_from ActiveRecord::RecordNotFound, with: :not_found
 
   before_action :store_current_location, except: :raise_not_found, unless: :devise_controller?
+  before_action :set_locale, if: 'user_signed_in?'
 
   def raise_not_found
     raise ActionController::RoutingError, "No route matches #{params[:unmatched_route]}"
@@ -24,6 +25,12 @@ class ApplicationController < ActionController::Base
     store_location_for(:user, request.url)
   end
 
+  def set_locale
+    I18n.locale = current_user.locale || I18n.default_locale
+  rescue I18n::InvalidLocale
+    I18n.locale = I18n.default_locale
+  end
+
   protected
 
   def not_found