class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
  before_filter :set_locale, :except => [:update_locale]

  def set_locale
    I18n.locale =  cookies[:locale] || extract_locale_from_accept_language_header || I18n.default_locale
  end


  private
  def extract_locale_from_accept_language_header
    language = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
    language = "zh-CN" if language.include?("zh")
  end
end
