Last active
March 30, 2016 09:40
-
-
Save jordifierro/bad03cc0e0f525542bd625d7fc3b79f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Api::V1::Concerns | |
module Internationalizator | |
extend ActiveSupport::Concern | |
included do | |
before_action :set_locale | |
end | |
def set_locale | |
I18n.locale = extract_locale_from_accept_language_header || | |
I18n.default_locale | |
end | |
def extract_locale_from_accept_language_header | |
req_lang = request.env['HTTP_ACCEPT_LANGUAGE'] | |
if req_lang | |
language = req_lang.scan(/^[a-z]{2}/).first | |
language if I18n.available_locales.include?(language.to_sym) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment