logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

localized.rb (753B)


  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. if ENV['DEFAULT_LOCALE'].present?
  16. I18n.default_locale
  17. else
  18. request_locale || I18n.default_locale
  19. end
  20. end
  21. def request_locale
  22. preferred_locale || compatible_locale
  23. end
  24. def preferred_locale
  25. http_accept_language.preferred_language_from(I18n.available_locales)
  26. end
  27. def compatible_locale
  28. http_accept_language.compatible_language_from(I18n.available_locales)
  29. end
  30. end