about summary refs log tree commit diff
path: root/app/controllers/concerns/localized.rb
diff options
context:
space:
mode:
authorShel R <Yiskah.Raphen@gmail.com>2017-04-07 22:33:40 -0400
committerGitHub <noreply@github.com>2017-04-07 22:33:40 -0400
commitd7d165db5b1b7b1959a36e1f0e3da875befc2574 (patch)
tree5be0ded23cf8a3190a3173bd5b16f4c4af77207f /app/controllers/concerns/localized.rb
parent73b8e67f4b103fc3400064d153807d6d88f758d4 (diff)
parentd7f4300ee3ff44a42453ea8042034d651a9789da (diff)
Merge branch 'master' into add-infinimatix.net-instance
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