Class: Rack::Locale
- Inherits:
-
Object
- Object
- Rack::Locale
- Defined in:
- lib/rack/contrib/locale.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Locale
constructor
A new instance of Locale.
Constructor Details
#initialize(app) ⇒ Locale
Returns a new instance of Locale.
10 11 12 |
# File 'lib/rack/contrib/locale.rb', line 10 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rack/contrib/locale.rb', line 14 def call(env) locale_to_restore = I18n.locale locale = user_preferred_locale(env["HTTP_ACCEPT_LANGUAGE"]) locale ||= I18n.default_locale env['rack.locale'] = I18n.locale = locale.to_s status, headers, body = @app.call(env) headers = HEADERS_KLASS.new.merge(headers) unless headers['Content-Language'] headers['Content-Language'] = locale.to_s end [status, headers, body] ensure I18n.locale = locale_to_restore end |