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.
 
 
 
 
 

26 lines
490 B

class LanguagesController < ApplicationController
before_action :set_locale_to_default
helper_method :accept_language
def index
end
private
def accept_language
@accept_language ||= request.env['HTTP_ACCEPT_LANGUAGE'].to_s.split(',').map { |l|
lang, q_factor = l.split(';q=')
[lang, (q_factor || '1').to_f]
}.sort_by { |_, q| -q }.map(&:first).first&.split('-')&.first
end
def set_locale_to_default
I18n.locale = I18n.default_locale
end
end