class ApplicationController < ActionController::Base
  include Authentication
  include Pagy::Backend
  around_action :set_time_zone
  around_action :switch_locale

  private

  def set_time_zone
    Time.use_zone("Beijing") { yield }
  end

  def switch_locale(&action)
    locale = cookies[:user_locale] || I18n.default_locale
    I18n.with_locale(locale, &action)
  rescue I18n::InvalidLocale
    I18n.with_locale(:en, &action)
  end
end
