class Rack::Locale

Public Instance Methods

call(env) click to toggle source
# File lib/rack/contrib/locale.rb, line 9
def call(env)
  old_locale = I18n.locale

  begin
    locale = accept_locale(env) || I18n.default_locale
    locale = env['rack.locale'] = I18n.locale = locale.to_s
    status, headers, body = @app.call(env)
    headers['Content-Language'] = locale unless headers['Content-Language']
    [status, headers, body]
  ensure
    I18n.locale = old_locale
  end
end

Public Class Methods

new(app) click to toggle source
# File lib/rack/contrib/locale.rb, line 5
def initialize(app)
  @app = app
end