master
 1module Internationalizationable
 2  extend ActiveSupport::Concern
 3
 4  included do
 5    around_action :with_time_zone, if: :current_user
 6    around_action :with_locale
 7  end
 8
 9  private
10
11  def with_time_zone
12    Time.use_zone(current_user.time_zone) { yield }
13  end
14
15  def with_locale
16    I18n.with_locale(current_locale) { yield }
17  end
18
19  def current_locale(locales = I18n.available_locales)
20    params[:locale] || http_accept_language.compatible_language_from(locales)
21  end
22end