openstreetmap-website/vendor/plugins/http_accept_language
Tom Hughes f0d3831f12 Escape language codes before matching them in case they contain
characters with special meaning in a regexp. Closes #2318.
2009-09-26 22:39:09 +00:00
..
lib Escape language codes before matching them in case they contain 2009-09-26 22:39:09 +00:00
tasks First stage of i18n. Some migrations and extra plugins. 2009-05-22 18:36:17 +00:00
test First stage of i18n. Some migrations and extra plugins. 2009-05-22 18:36:17 +00:00
init.rb First stage of i18n. Some migrations and extra plugins. 2009-05-22 18:36:17 +00:00
MIT-LICENSE First stage of i18n. Some migrations and extra plugins. 2009-05-22 18:36:17 +00:00
Rakefile First stage of i18n. Some migrations and extra plugins. 2009-05-22 18:36:17 +00:00
README.rdoc First stage of i18n. Some migrations and extra plugins. 2009-05-22 18:36:17 +00:00

= 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: http://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_language
      # => [ 'en-GB']
      available = %w{en-US}
      request.compatible_language_from(available)
      # => 'en-US'
    end
  end

= Changenotes

2009-03-12: Rails 2.3 compatible

Copyright (c) 2008 Iain Hecker, released under the MIT license