diff options
author | Robin Houston <robin.houston@gmail.com> | 2012-08-01 11:31:53 +0100 |
---|---|---|
committer | Robin Houston <robin.houston@gmail.com> | 2012-08-01 11:31:53 +0100 |
commit | cc3268df4c9de319ea16aa99238e3c4c40dae7c5 (patch) | |
tree | 3415a1c6725973656d569558036d8225ac520286 | |
parent | 021137133cd6f496b83278c2eebb558223843b7f (diff) |
Move variable restore to an ensure block
I think this whole thing is redundant anyway, since the locale is
set at the start of each request, but if we’re going to save/restore
this value then we might as well do so correctly.
-rw-r--r-- | app/controllers/services_controller.rb | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index 00c0e61bd..8fa860fb2 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -9,15 +9,19 @@ class ServicesController < ApplicationController if country_from_ip.downcase != iso_country_code found_country = WorldFOIWebsites.by_code(country_from_ip) found_country_name = !found_country.nil? && found_country[:country_name] - old_locale = FastGettext.locale - FastGettext.locale = FastGettext.best_locale_in(request.env['HTTP_ACCEPT_LANGUAGE']) - if found_country_name - text = _("Hello! You can make Freedom of Information requests within {{country_name}} at {{link_to_website}}", :country_name => found_country_name, :link_to_website => "<a href=\"#{found_country[:url]}\">#{found_country[:name]}</a>") - else - current_country = WorldFOIWebsites.by_code(iso_country_code)[:country_name] - text = _("Hello! We have an <a href=\"/help/alaveteli?country_name=#{CGI.escape(current_country)}\">important message</a> for visitors outside {{country_name}}", :country_name => current_country) + + old_fgt_locale = FastGettext.locale + begin + FastGettext.locale = FastGettext.best_locale_in(request.env['HTTP_ACCEPT_LANGUAGE']) + if found_country_name + text = _("Hello! You can make Freedom of Information requests within {{country_name}} at {{link_to_website}}", :country_name => found_country_name, :link_to_website => "<a href=\"#{found_country[:url]}\">#{found_country[:name]}</a>") + else + current_country = WorldFOIWebsites.by_code(iso_country_code)[:country_name] + text = _("Hello! We have an <a href=\"/help/alaveteli?country_name=#{CGI.escape(current_country)}\">important message</a> for visitors outside {{country_name}}", :country_name => current_country) + end + ensure + FastGettext.locale = old_fgt_locale end - FastGettext.locale = old_locale end if !text.empty? text += ' <span class="close-button">X</span>' |