diff options
-rw-r--r-- | app/controllers/services_controller.rb | 3 | ||||
-rw-r--r-- | spec/controllers/services_controller_spec.rb | 8 |
2 files changed, 8 insertions, 3 deletions
diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index 28dd2143d..00c0e61bd 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -9,12 +9,15 @@ 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) end + FastGettext.locale = old_locale end if !text.empty? text += ' <span class="close-button">X</span>' diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index 1bafd0c8f..2be382258 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe ServicesController, "when using web services" do @@ -16,15 +17,16 @@ describe ServicesController, "when using web services" do config['ISO_COUNTRY_CODE'] = "DE" controller.stub!(:country_from_ip).and_return('ZZ') get :other_country_message - response.body.should match(/outside Germany/) + response.body.should match(/outside Deutschland/) end it "should show link to other FOI website when not in the deployed country" do config = MySociety::Config.load_default() config['ISO_COUNTRY_CODE'] = "ZZ" - controller.stub!(:country_from_ip).and_return('DE') + controller.stub!(:country_from_ip).and_return('ES') + request.env['HTTP_ACCEPT_LANGUAGE'] = "es" get :other_country_message - response.body.should match(/within Germany/) + response.body.should match(/Puede hacer solicitudes de información en España/) end |