github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

iain / http_accept_language

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 93
    • 9
  • Source
  • Commits
  • Network (9)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Ruby on Rails plugin. Fishes out the Accept-Language header into an array. — Read more

  cancel

http://rails-i18n.org/

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Remove dead code 
iain (author)
Tue Jan 05 03:10:05 -0800 2010
commit  b2160fbf40f495f5ce6615aea21284829b87c9eb
tree    a2d4cee91718d7aa77a20a50e1032c292c8577a9
parent  2c759860eac6ce9ee0c743bb4b40aa7371087431
http_accept_language /
name age
history
message
file .gitignore Tue Jan 05 03:06:38 -0800 2010 Add gemspec [iain]
file README.rdoc Tue Jan 05 03:04:34 -0800 2010 Preparing to release as a gem [iain]
file Rakefile Tue Jan 05 03:04:34 -0800 2010 Preparing to release as a gem [iain]
file VERSION Tue Jan 05 03:01:53 -0800 2010 Version bump to 1.0.0 [iain]
file http_accept_language.gemspec Tue Jan 05 03:06:38 -0800 2010 Add gemspec [iain]
directory lib/ Thu Mar 12 14:56:15 -0700 2009 Return the first of user compatible locales. Ad... [iain]
directory rails/ Tue Jan 05 03:04:34 -0800 2010 Preparing to release as a gem [iain]
directory test/ Thu Mar 12 14:56:15 -0700 2009 Return the first of user compatible locales. Ad... [iain]
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

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server