require 'active_support/concern' module Tenzing module Localizer extend ActiveSupport::Concern included do before_filter :set_locale rescue_from I18n::InvalidLocale, with: :invalid_locale end def set_locale locale = params[:lang] locale ||= session[:locale] locale ||= ((lang = request.env['HTTP_ACCEPT_LANGUAGE']) && lang[/^[a-z]{2}/]) locale ||= I18n.default_locale I18n.locale = locale session[:locale] = I18n.locale end def invalid_locale(e) flash[:error] = e.message redirect_to root_url end end end