The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

29 lines
558 B

  1. # frozen_string_literal: true
  2. module Localized
  3. extend ActiveSupport::Concern
  4. included do
  5. before_action :set_locale
  6. end
  7. private
  8. def set_locale
  9. I18n.locale = default_locale
  10. I18n.locale = current_user.locale if user_signed_in?
  11. rescue I18n::InvalidLocale
  12. I18n.locale = default_locale
  13. end
  14. def default_locale
  15. ENV.fetch('DEFAULT_LOCALE') do
  16. user_supplied_locale || I18n.default_locale
  17. end
  18. end
  19. def user_supplied_locale
  20. http_accept_language.language_region_compatible_from(I18n.available_locales)
  21. end
  22. end