iain / http_accept_language
- Source
- Commits
- Network (9)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Tue Jan 05 03:06:38 -0800 2010 | |
| |
README.rdoc | Tue Jan 05 03:04:34 -0800 2010 | |
| |
Rakefile | Tue Jan 05 03:04:34 -0800 2010 | |
| |
VERSION | Tue Jan 05 03:01:53 -0800 2010 | |
| |
http_accept_language.gemspec | Tue Jan 05 03:06:38 -0800 2010 | |
| |
lib/ | Thu Mar 12 14:56:15 -0700 2009 | |
| |
rails/ | Tue Jan 05 03:04:34 -0800 2010 | |
| |
test/ | Thu Mar 12 14:56:15 -0700 2009 |
README.rdoc
HttpAcceptLanguage
A small effort in making a plugin which helps you detect the users preferred language, as sent by the HTTP header.
Features
- Splits the http-header into languages specified by the user
- Returns empty array if header is illformed.
- Corrects case to xx-XX
- Sorted by priority given, as much as possible.
- Gives you the most important language
- Gives compatible languages
See also: www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
Example
class SomeController < ApplicationController
def some_action
request.user_preferred_languages
# => [ 'nl-NL', 'nl-BE', 'nl', 'en-US', 'en' ]
available = %w{en en-US nl-BE}
request.preferred_language_from(available)
# => 'nl-BE'
request.user_preferred_languages
# => [ 'en-GB']
available = %w{en-US}
request.compatible_language_from(available)
# => 'en-US'
end
end
Installation
Install the gem http_accept_language, require it in your Rails app.
Changelog
- 2010-01-05: Gem release
- 2009-03-12: Rails 2.3 compatible
Copyright © 2008-2010 Iain Hecker, released under the MIT license
