From 9b746bd34b2b6d0ba71fd740a83f4c6d2da123f0 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 12 Jan 2011 15:22:15 +0000 Subject: initial, basic i18n support with gettext --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9382e077f..61a2444e3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,7 +12,7 @@ class ApplicationController < ActionController::Base # Standard headers, footers and navigation for whole site layout "default" - # set locale + 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 -- cgit v1.2.3 From acd7b81f4cfaf2db204f1aee1e2e2d21d549db88 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Thu, 13 Jan 2011 17:41:44 +0000 Subject: top-level gettext functions already available --- app/controllers/application_controller.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 61a2444e3..4252d4212 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,7 +12,6 @@ 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 -- cgit v1.2.3 From 59462ac90b067dd67b0908b9924b23eb74a505bd Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Thu, 13 Jan 2011 19:18:56 +0000 Subject: make site_name a globally available helper --- app/controllers/application_controller.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4252d4212..1628d2f31 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -13,9 +13,17 @@ class ApplicationController < ActionController::Base # Standard headers, footers and navigation for whole site layout "default" 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 + # 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. -- cgit v1.2.3 From cf5b70fe37a35a410cd562d4f7d5653f7d4655cb Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Thu, 13 Jan 2011 17:41:44 +0000 Subject: top-level gettext functions already available --- app/controllers/application_controller.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1628d2f31..0ec8daf0a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,6 +12,7 @@ class ApplicationController < ActionController::Base # Standard headers, footers and navigation for whole site layout "default" + before_filter :set_gettext_locale # scrub sensitive parameters from the logs @@ -24,6 +25,8 @@ class ApplicationController < ActionController::Base return site_name end + include FastGettext::Translation # make functions like _, n_, N_ etc available) + # 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. -- cgit v1.2.3 From f09146ff3321c57e1b176d47c6dbe0d58b611c41 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Thu, 13 Jan 2011 19:18:56 +0000 Subject: make site_name a globally available helper --- app/controllers/application_controller.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0ec8daf0a..c4db7469f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -27,6 +27,16 @@ class ApplicationController < ActionController::Base include FastGettext::Translation # make functions like _, n_, N_ etc available) + before_filter :set_gettext_locale + + helper_method :site_name + 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. -- cgit v1.2.3 From da7bbcf5ec0caaef72e6e6622cf4247092b6ea30 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 25 Feb 2011 14:36:26 +0000 Subject: move locale-setting logic locally (are likely to want to override it) --- app/controllers/application_controller.rb | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'app/controllers/application_controller.rb') 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 -- cgit v1.2.3