3 A small effort in making a plugin which helps you detect the users preferred language, as sent by the HTTP header.
7 * Splits the http-header into languages specified by the user
8 * Returns empty array if header is illformed.
9 * Corrects case to xx-XX
10 * Sorted by priority given, as much as possible.
11 * Gives you the most important language
12 * Gives compatible languages
13 See also: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
17 class SomeController < ApplicationController
20 request.user_preferred_languages
21 # => [ 'nl-NL', 'nl-BE', 'nl', 'en-US', 'en' ]
23 available = %w{en en-US nl-BE}
24 request.preferred_language_from(available)
27 request.user_preferred_languages
30 request.compatible_language_from(available)
37 Install the gem <tt>http_accept_language</tt>, require it in your Rails app.
41 * 2010-01-05: Gem release
42 * 2009-03-12: Rails 2.3 compatible
44 Copyright (c) 2008-2010 Iain Hecker, released under the MIT license