Class: Rack::I18nRoutes
- Inherits:
-
Object
- Object
- Rack::I18nRoutes
- Defined in:
- lib/rack/i18n_routes.rb
Overview
A middleware component to route translated URLs to their canonical URL.
Constant Summary collapse
- ORIG_PATH_INFO_VARIABLE =
'rack.i18n_routes_orig_PATH_INFO'
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, path_lookup) ⇒ I18nRoutes
constructor
Set up an i18n routing table.
Constructor Details
#initialize(app, url_mapper) ⇒ I18nRoutes #initialize(app, url_mapping_fn) ⇒ I18nRoutes
Set up an i18n routing table.
105 106 107 108 109 |
# File 'lib/rack/i18n_routes.rb', line 105 def initialize(app, path_lookup) @app = app @path_lookup = path_lookup end |
Instance Method Details
#call(env) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/rack/i18n_routes.rb', line 111 def call(env) path = env['PATH_INFO'] normalized_path = if @path_lookup.respond_to?(:map) @path_lookup.map(path) else @path_lookup[path] end env[ORIG_PATH_INFO_VARIABLE] = path env['PATH_INFO'] = normalized_path return @app.call(env) end |