aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeb Bacon <seb.bacon@gmail.com>2011-08-08 15:24:01 +0100
committerSeb Bacon <seb.bacon@gmail.com>2011-08-08 15:24:01 +0100
commitd5e1fc1c612e8edf6c571d019cf68ba66b3bee64 (patch)
tree5df6619a8dc2e887283bac57d43dd51b4a67d3cf
parent8d079ca778e2905a61c947648d924cb6c4f79724 (diff)
Introduce config setting to ignore browser language settings
-rw-r--r--app/controllers/application_controller.rb6
-rw-r--r--config/general.yml-example1
-rw-r--r--spec/controllers/general_controller_spec.rb16
3 files changed, 21 insertions, 2 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 2918f39c0..0d8c83d6c 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -42,7 +42,11 @@ class ApplicationController < ActionController::Base
end
def set_gettext_locale
- requested_locale = params[:locale] || session[:locale] || cookies[:locale] || request.env['HTTP_ACCEPT_LANGUAGE'] || I18n.default_locale
+ if MySociety::Config.get('USE_DEFAULT_BROWSER_LANGUAGE', true)
+ requested_locale = params[:locale] || session[:locale] || cookies[:locale] || request.env['HTTP_ACCEPT_LANGUAGE'] || I18n.default_locale
+ else
+ requested_locale = params[:locale] || session[:locale] || cookies[:locale] || I18n.default_locale
+ end
session[:locale] = FastGettext.set_locale(requested_locale)
end
diff --git a/config/general.yml-example b/config/general.yml-example
index 9db95c4d0..729278a8d 100644
--- a/config/general.yml-example
+++ b/config/general.yml-example
@@ -19,6 +19,7 @@ TWITTER_USERNAME: 'whatdotheyknow'
# Locales we wish to support in this app, space-delimited
AVAILABLE_LOCALES: 'en es'
DEFAULT_LOCALE: 'en'
+USE_DEFAULT_BROWSER_LANGUAGE: true
# How many days should have passed before an answer to a request is officially late?
REPLY_LATE_AFTER_DAYS: 20
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index 63ad6873c..bc744a9cd 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -30,7 +30,21 @@ describe GeneralController, "when searching" do
I18n.default_locale = old_default_locale
end
- it "should render the front page with browser-selected language" do
+ it "should render the front page with default language and ignore the browser setting" do
+ config = MySociety::Config.load_default()
+ config['USE_DEFAULT_BROWSER_LANGUAGE'] = false
+ accept_language = "en-GB,en-US;q=0.8,en;q=0.6"
+ request.env['HTTP_ACCEPT_LANGUAGE'] = accept_language
+ old_default_locale = I18n.default_locale
+ I18n.default_locale = "es"
+ get :frontpage
+ response.should have_tag('html[lang="es"]')
+ I18n.default_locale = old_default_locale
+ end
+
+ it "should render the front page with browser-selected language when there's no default set" do
+ config = MySociety::Config.load_default()
+ config['USE_DEFAULT_BROWSER_LANGUAGE'] = true
accept_language = "es-ES,en-GB,en-US;q=0.8,en;q=0.6"
request.env['HTTP_ACCEPT_LANGUAGE'] = accept_language
get :frontpage