No commit activity in last 3 years
No release in over 3 years
Rack::LocaleRootRedirect uses Rack:Accept to map '/' to a path based on the `Accept-Language` HTTP header.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
~> 3.1
= 0.29

Runtime

>= 0.4.5
 Project Readme

Rack::LocaleRootRedirect

Rack::LocaleRootRedirect redirects requests to "/" based on the Accept-Language HTTP header.

Installation

Add this line to your application’s Gemfile:

gem 'rack-locale-root-redirect'

And then execute:

$ bundle

Usage

Add the rack-locale-root-redirect gem in your Gemfile.

gem 'rack-locale-root-redirect'

With Ruby on Rails

Add these lines in your config/application.rb file, along other configuration instructions.

config.use Rack::Accept
config.use Rack::LocaleRootRedirect, fr: '/fr', en: '/en'

With Sinatra

Add these lines in your config.ru file, or wherever your Sinatra application is located.

use Rack::Accept
use Rack::LocaleRootRedirect, fr: '/fr', en: '/en'

The result

$ rackup &

$ curl -sI "http://0.0.0.0:9292" -H "Accept-Language: fr;q=1, en;q=0.8" | grep "302\|Location"
HTTP/1.1 302 Found
Location: /fr

$ curl -sI "http://0.0.0.0:9292" -H "Accept-Language: fr;q=0.4, en;q=0.8" | grep "302\|Location"
HTTP/1.1 302 Found
Location: /en

License

Rack::LocaleRootRedirect is © 2013-2015 Mirego and may be freely distributed under the New BSD license. See the LICENSE.md file.

About Mirego

Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We're a team of talented people who imagine and build beautiful Web and mobile applications. We come together to share ideas and change the world.

We also love open-source software and we try to give back to the community as much as we can.