diff options
author | Seb Bacon <seb.bacon@gmail.com> | 2011-02-25 14:36:26 +0000 |
---|---|---|
committer | Seb Bacon <seb.bacon@gmail.com> | 2011-03-10 10:53:26 +0000 |
commit | da7bbcf5ec0caaef72e6e6622cf4247092b6ea30 (patch) | |
tree | 170fb38f6579116bb3d96d11b39cc391daa1735a /app/controllers/application_controller.rb | |
parent | 9fc120d3e08c9d7ea1522838103f83bd87eeba59 (diff) |
move locale-setting logic locally (are likely to want to override it)
Diffstat (limited to 'app/controllers/application_controller.rb')
-rw-r--r-- | app/controllers/application_controller.rb | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c4db7469f..91754e2ba 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,31 +12,28 @@ class ApplicationController < ActionController::Base # Standard headers, footers and navigation for whole site layout "default" - + include FastGettext::Translation # make functions like _, n_, N_ etc available) before_filter :set_gettext_locale # scrub sensitive parameters from the logs filter_parameter_logging :password - helper_method :site_name - def site_name - # XXX should come from database: - site_name = "WhatDoTheyKnow" - return site_name - end - include FastGettext::Translation # make functions like _, n_, N_ etc available) + def set_gettext_locale + requested_locale = params[:locale] || session[:locale] || cookies[:locale] || request.env['HTTP_ACCEPT_LANGUAGE'] + session[:locale] = FastGettext.set_locale(requested_locale) + end - before_filter :set_gettext_locale + # scrub sensitive parameters from the logs + filter_parameter_logging :password - helper_method :site_name + helper_method :site_name, :locale_from_params def site_name # XXX should come from database: site_name = "WhatDoTheyKnow" return site_name end - # Help work out which request causes RAM spike. # http://www.codeweblog.com/rails-to-monitor-the-process-of-memory-leaks-skills/ # This shows the memory use increase of the Ruby process due to the request. @@ -151,6 +148,16 @@ class ApplicationController < ActionController::Base f.write(content) end end + + # get the local locale + def locale_from_params(*args) + if params[:show_locale] + params[:show_locale] + else + I18n.locale.to_s + end + end + private # Check the user is logged in |