Locale Chooser - A Rack Middleware for Locale Selection

Priority

Cookie Setting > Geolocation > HTTP Accept Language Header > Default

Prerequisites


GeoIP C API Installed: www.maxmind.com/app/c GeoIP Ruby Wrapper Installed: rubyforge.org/scm/?group_id=947


Install

gem install rack-locale_chooser


Example for Rails Use on some enviroment file:

config.gem ‘rack-locale_chooser’

config.middleware.use ‘Rack::LocaleChooser’, :geodb_path => ‘/usr/local/share/GeoIP/GeoLiteCity.dat’,

:default_domain => 'example.com', 
:host_mappings => { :es => 'es.example.com', 
                    :pt_BR => 'br.example.com'
                  },
:country_mappings => { 'BR' => :pt_BR, 'MX' => :es }

Params

host_mappings -> Mapping from locale to host for url rewriting country_mappings -> Mapping from country codes returned by GeoIP to locales default_domain -> default domain for cookie setting geodb_path -> path for GeoIP dat file