gem 'open_id_authentication', '>= 1.1.0'
gem 'validates_email_format_of', '>= 1.5.1'
gem 'composite_primary_keys', '>= 4.1.2'
+gem 'http_accept_language', '>= 1.0.2'
# Character conversion support for ruby 1.8
gem 'iconv', :platforms => :ruby_18
multipart-post (~> 1.1)
rack (~> 1.1)
hike (1.2.1)
+ http_accept_language (1.0.2)
httpclient (2.2.4)
i18n (0.6.0)
iconv (0.1)
coffee-rails (~> 3.2.1)
composite_primary_keys (>= 4.1.2)
dynamic_form
+ http_accept_language (>= 1.0.2)
httpclient
iconv
jquery-rails
--- /dev/null
+#
+# Monkey patch HttpAcceptLanguage pending integration of
+# https://github.com/iain/http_accept_language/pull/6
+#
+module HttpAcceptLanguage
+ def compatible_language_from(available_languages)
+ user_preferred_languages.find do |x|
+ available_languages.find { |y| y.to_s == x.to_s } ||
+ available_languages.find { |y| y.to_s =~ /^#{Regexp.escape(x.to_s)}-/ }
+ end
+ end
+end
+++ /dev/null
-= 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_languages
- # => [ 'en-GB']
- available = %w{en-US}
- request.compatible_language_from(available)
- # => 'en-US'
- end
- end
-
-== Installation
-
-Install the gem <tt>http_accept_language</tt>, require it in your Rails app.
-
-== Changelog
-
-* 2010-01-05: Gem release
-* 2009-03-12: Rails 2.3 compatible
-
-Copyright (c) 2008-2010 Iain Hecker, released under the MIT license
+++ /dev/null
-require 'rake'
-
-begin
- require 'jeweler'
- Jeweler::Tasks.new do |gem|
- gem.name = "http_accept_language"
- gem.summary = %Q{Parse the HTTP Accept Language Header}
- gem.description = %Q{Find out which locale the user preferes by reading the languages they specified in their browser}
- gem.email = "iain@iain.nl"
- gem.homepage = "http://github.com/iain/http_accept_language"
- gem.authors = ["Iain Hecker"]
- end
- Jeweler::GemcutterTasks.new
-rescue LoadError
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
-end
-
-require 'rake/testtask'
-desc 'Test the http_accept_language plugin.'
-Rake::TestTask.new(:test) do |t|
- t.libs << 'lib'
- t.pattern = 'test/**/*_test.rb'
- t.verbose = true
-end
-
-desc 'Default: run unit tests.'
-task :default => :test
-
-require 'rake/rdoctask'
-desc 'Generate documentation for the http_accept_language plugin.'
-Rake::RDocTask.new(:rdoc) do |rdoc|
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = 'HttpAcceptLanguage'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README')
- rdoc.rdoc_files.include('lib/**/*.rb')
-end
+++ /dev/null
-if defined?(ActionDispatch::Request)
- ActionDispatch::Request.send :include, HttpAcceptLanguage
-elsif defined?(ActionController::Request)
- ActionController::Request.send :include, HttpAcceptLanguage
-elsif defined?(ActionController::AbstractRequest)
- ActionController::AbstractRequest.send :include, HttpAcceptLanguage
-else
- ActionController::CgiRequest.send :include, HttpAcceptLanguage
-end
+++ /dev/null
-module HttpAcceptLanguage
-
- # Returns a sorted array based on user preference in HTTP_ACCEPT_LANGUAGE.
- # Browsers send this HTTP header, so don't think this is holy.
- #
- # Example:
- #
- # request.user_preferred_languages
- # # => [ 'nl-NL', 'nl-BE', 'nl', 'en-US', 'en' ]
- #
- def user_preferred_languages
- @user_preferred_languages ||= env['HTTP_ACCEPT_LANGUAGE'].split(',').collect do |l|
- l += ';q=1.0' unless l =~ /;q=\d+\.\d+$/
- l.split(';q=')
- end.sort do |x,y|
- raise "Not correctly formatted" unless x.first =~ /^[a-z\-]+$/i
- y.last.to_f <=> x.last.to_f
- end.collect do |l|
- l.first.downcase.gsub(/-[a-z]+$/i) { |x| x.upcase }
- end
- rescue # Just rescue anything if the browser messed up badly.
- []
- end
-
- # Sets the user languages preference, overiding the browser
- #
- def user_preferred_languages=(languages)
- @user_preferred_languages = languages
- end
-
- # Finds the locale specifically requested by the browser.
- #
- # Example:
- #
- # request.preferred_language_from I18n.available_locales
- # # => 'nl'
- #
- def preferred_language_from(array)
- (user_preferred_languages & array.collect { |i| i.to_s }).first
- end
-
- # Returns the first of the user_preferred_languages that is compatible
- # with the available locales. Ignores region.
- #
- # Example:
- #
- # request.compatible_language_from I18n.available_locales
- #
- def compatible_language_from(array)
- user_preferred_languages.find do |x|
- array.find { |y| y.to_s == x.to_s } ||
- array.find { |y| y.to_s =~ /^#{Regexp.escape(x.to_s)}-/ }
- end
- end
-
-end
+++ /dev/null
-$:.unshift(File.dirname(__FILE__) + '/../lib')
-require 'http_accept_language'
-require 'test/unit'
-
-class MockedCgiRequest
- include HttpAcceptLanguage
- def env
- @env ||= {'HTTP_ACCEPT_LANGUAGE' => 'en-us,en-gb;q=0.8,en;q=0.6'}
- end
-end
-
-class HttpAcceptLanguageTest < Test::Unit::TestCase
- def test_should_return_empty_array
- request.env['HTTP_ACCEPT_LANGUAGE'] = nil
- assert_equal [], request.user_preferred_languages
- end
-
- def test_should_properly_split
- assert_equal %w{en-US en-GB en}, request.user_preferred_languages
- end
-
- def test_should_ignore_jambled_header
- request.env['HTTP_ACCEPT_LANGUAGE'] = 'odkhjf89fioma098jq .,.,'
- assert_equal [], request.user_preferred_languages
- end
-
- def test_should_find_first_available_language
- assert_equal 'en-GB', request.preferred_language_from(%w{en en-GB})
- end
-
- def test_should_find_first_compatible_language
- assert_equal 'en-hk', request.compatible_language_from(%w{en-hk})
- assert_equal 'en', request.compatible_language_from(%w{en})
- end
-
- def test_should_find_first_compatible_from_user_preferred
- request.env['HTTP_ACCEPT_LANGUAGE'] = 'en-us,de-de'
- assert_equal 'en', request.compatible_language_from(%w{de en})
- end
-
- private
- def request
- @request ||= MockedCgiRequest.new
- end
-end