Skip to content

Instantly share code, notes, and snippets.

@yoshitsugu
Last active December 20, 2015 06:39
Show Gist options
  • Save yoshitsugu/6087774 to your computer and use it in GitHub Desktop.
Save yoshitsugu/6087774 to your computer and use it in GitHub Desktop.
rails application_controller set_locale
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :set_locale
protected
def set_locale
logger.debug "* Accept-Language: #{request.env['HTTP_ACCEPT_LANGUAGE']}"
I18n.locale = params[:locale] ||
extract_locale_from_accept_language_header ||
I18n.default_locale
logger.debug "* Locale set to '#{I18n.locale}'"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment