Skip to content
Snippets Groups Projects
Commit 24184142 authored by Alex Reisner's avatar Alex Reisner
Browse files

Merge pull request #655 from mkristian/language_pre_request

allow to pass in language/locale parameter on per request base
parents 472e7606 02d928f9
No related branches found
No related tags found
No related merge requests found
......@@ -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('|')
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -98,6 +98,10 @@ module Geocoder
coordinates?
end
def language
options[:language]
end
private # ----------------------------------------------------------------
def params_given?
......
......@@ -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|
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment