0

I am trying to set up internationalization in my rails app. Use this article https://lingohub.com/blog/2013/08/internationalization-for-ruby-i18n-gem/

But I have error:

Failure/Error: http_accept_language.scan(/^[a-z]{2}/).first

     NoMethodError:
       undefined method `scan' for :en:Symbol

My aplication controller:

def set_locale
  I18n.locale = extract_locale_from_accept_language_header
end

private
def extract_locale_from_accept_language_header
  request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
end

What could be the problem?

alexin
  • 243
  • 1
  • 15

1 Answers1

1

Ruby strings will respond to #scan, but not symbols. Try calling #to_s on the header value as below:

def extract_locale_from_accept_language_header
  request.env['HTTP_ACCEPT_LANGUAGE'].to_s.scan(/^[a-z]{2}/).first
end
rossta
  • 11,394
  • 1
  • 43
  • 47