about summary refs log tree commit diff
path: root/app/controllers/concerns/localized.rb
diff options
context:
space:
mode:
authorValentin Ouvrard <valentin210594@gmail.com>2017-04-08 13:39:09 +1100
committerGitHub <noreply@github.com>2017-04-08 13:39:09 +1100
commit3e4eb9c95fc8d8f3fff1db90215d5050214adc59 (patch)
treec9f709f2582f8fe97c72b4faa8bc0811bbbb4deb /app/controllers/concerns/localized.rb
parent93e53a3311c33b218d1cf7ae26b74056dfabc909 (diff)
parentfc7b8307190b8f472b526d99bc10db58153850d5 (diff)
Merge branch 'master' into master
Diffstat (limited to 'app/controllers/concerns/localized.rb')
-rw-r--r--app/controllers/concerns/localized.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/app/controllers/concerns/localized.rb b/app/controllers/concerns/localized.rb
new file mode 100644
index 000000000..b6f868090
--- /dev/null
+++ b/app/controllers/concerns/localized.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+module Localized
+  extend ActiveSupport::Concern
+
+  included do
+    before_action :set_locale
+  end
+
+  def set_locale
+    I18n.locale = current_user.try(:locale) || default_locale
+  rescue I18n::InvalidLocale
+    I18n.locale = default_locale
+  end
+
+  def default_locale
+    ENV.fetch('DEFAULT_LOCALE') { I18n.default_locale }
+  end
+end