You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
367 B

  1. # frozen_string_literal: true
  2. module Localized
  3. extend ActiveSupport::Concern
  4. included do
  5. before_action :set_locale
  6. end
  7. def set_locale
  8. I18n.locale = current_user.try(:locale) || default_locale
  9. rescue I18n::InvalidLocale
  10. I18n.locale = default_locale
  11. end
  12. def default_locale
  13. ENV.fetch('DEFAULT_LOCALE') { I18n.default_locale }
  14. end
  15. end