diff --git a/lib/geocoder/lookups/google.rb b/lib/geocoder/lookups/google.rb index d87f79bf506eaacd8d9bef4d65cefc5d1acd4051..ef1e41c75cdab9f1498263f405de10cb6696a951 100644 --- a/lib/geocoder/lookups/google.rb +++ b/lib/geocoder/lookups/google.rb @@ -44,7 +44,7 @@ module Geocoder::Lookup params = { (query.reverse_geocode? ? :latlng : :address) => query.sanitized_text, :sensor => "false", - :language => configuration.language + :language => (query.language || configuration.language) } unless (bounds = query.options[:bounds]).nil? params[:bounds] = bounds.map{ |point| "%f,%f" % point }.join('|') diff --git a/lib/geocoder/lookups/nominatim.rb b/lib/geocoder/lookups/nominatim.rb index 4e594862bacf836b0433d9bfa20ddcd72a3e48e0..6eeef98946cf3393fb271d78581629c4d6010d0c 100644 --- a/lib/geocoder/lookups/nominatim.rb +++ b/lib/geocoder/lookups/nominatim.rb @@ -37,7 +37,7 @@ module Geocoder::Lookup params = { :format => "json", :addressdetails => "1", - :"accept-language" => configuration.language + :"accept-language" => (query.language || configuration.language) }.merge(super) if query.reverse_geocode? lat,lon = query.coordinates diff --git a/lib/geocoder/lookups/yahoo.rb b/lib/geocoder/lookups/yahoo.rb index 2b80100c3f5cafd3bc15a87f2a3a18c413a1681c..ec19f4fe6abe7de421502a4ba9423dafc2c464c1 100644 --- a/lib/geocoder/lookups/yahoo.rb +++ b/lib/geocoder/lookups/yahoo.rb @@ -62,11 +62,13 @@ module Geocoder::Lookup end def query_url_params(query) + lang = (query.language || configuration.language).to_s + lang += '_US' if lang == 'en' { :location => query.sanitized_text, :flags => "JXTSR", :gflags => "AC#{'R' if query.reverse_geocode?}", - :locale => "#{configuration.language}_US", + :locale => lang, :appid => configuration.api_key }.merge(super) end diff --git a/lib/geocoder/lookups/yandex.rb b/lib/geocoder/lookups/yandex.rb index f5559efbdd865ce4080358acd1b303595f1b1199..6be58770a74129539db4afdead083441ecd4d36c 100644 --- a/lib/geocoder/lookups/yandex.rb +++ b/lib/geocoder/lookups/yandex.rb @@ -46,7 +46,7 @@ module Geocoder::Lookup { :geocode => q, :format => "json", - :plng => "#{configuration.language}", # supports ru, uk, be + :plng => "#{query.language || configuration.language}", # supports ru, uk, be :key => configuration.api_key }.merge(super) end diff --git a/lib/geocoder/query.rb b/lib/geocoder/query.rb index d201c94fbe69c50ac12fe10dcb7e27248aa7efce..c8e8c298d07e2d3c7a067712245e8eda417d6aae 100644 --- a/lib/geocoder/query.rb +++ b/lib/geocoder/query.rb @@ -98,6 +98,10 @@ module Geocoder coordinates? end + def language + options[:language] + end + private # ---------------------------------------------------------------- def params_given? diff --git a/test/unit/lookup_test.rb b/test/unit/lookup_test.rb index 83561537ab8d37626e5fb4d2242439720966b9ce..ba7a14a373dd4b67f2a1a944fec6e4ec2bcccf30 100644 --- a/test/unit/lookup_test.rb +++ b/test/unit/lookup_test.rb @@ -56,6 +56,23 @@ class LookupTest < GeocoderTestCase end end + { + :google => :language, + :google_premier => :language, + :nominatim => :"accept-language", + :yahoo => :locale, + :yandex => :plng + }.each do |l,p| + define_method "test_passing_language_to_#{l}_query_overrides_configuration_value" do + set_api_key!(l) + url = Geocoder::Lookup.get(l).query_url(Geocoder::Query.new( + "test", :language => 'xxxx' + )) + assert_match(/#{p}=xxxx/, url, + "Param passed to #{l} lookup does not override configuration value") + end + end + def test_raises_exception_on_invalid_key Geocoder.configure(:always_raise => [Geocoder::InvalidApiKey]) #Geocoder::Lookup.all_services_except_test.each do |l|