gem 'open_id_authentication', '>= 1.1.0'
gem 'validates_email_format_of', '>= 1.5.1'
gem 'composite_primary_keys', '>= 6.0.0'
-gem 'http_accept_language', '~> 1.0.2'
+gem 'http_accept_language', '~> 2.0.0'
gem 'paperclip', '~> 3.0'
gem 'deadlock_retry', '>= 1.2.0'
gem 'openstreetmap-i18n-js', '>= 3.0.0.rc5.2', :require => 'i18n-js'
multipart-post (~> 1.2.0)
hike (1.2.3)
htmlentities (4.3.1)
- http_accept_language (1.0.2)
+ http_accept_language (2.0.0)
httpauth (0.2.0)
httpclient (2.3.4.1)
i18n (0.6.5)
dynamic_form
ejs
htmlentities
- http_accept_language (~> 1.0.2)
+ http_accept_language (~> 2.0.0)
httpclient
iconv (= 0.1)
jquery-rails
user = getuser(usertoken)
if user && !user.languages.empty?
- request.user_preferred_languages = user.languages
+ http_accept_language.user_preferred_languages = user.languages
end
- lang = request.compatible_language_from(getlocales)
+ lang = http_accept_language.compatible_language_from(getlocales)
(real_lang, localised) = getlocalized(lang)
# Tell Potlatch what language it's using
response.header['Vary'] = 'Accept-Language'
if @user && !@user.languages.empty?
- request.user_preferred_languages = @user.languages
+ http_accept_language.user_preferred_languages = @user.languages
response.header['Vary'] = '*'
end
I18n.locale = select_locale
- if @user && @user.languages.empty? && !request.user_preferred_languages.empty?
- @user.languages = request.user_preferred_languages
+ if @user && @user.languages.empty? && !http_accept_language.user_preferred_languages.empty?
+ @user.languages = http_accept_language.user_preferred_languages
@user.save
end
def select_locale(locales = I18n.available_locales)
if params[:locale]
- request.user_preferred_languages = [ params[:locale] ]
+ http_accept_language.user_preferred_languages = [ params[:locale] ]
end
- if request.compatible_language_from(locales).nil?
- request.user_preferred_languages = request.user_preferred_languages.collect do |pl|
+ if http_accept_language.compatible_language_from(locales).nil?
+ http_accept_language.user_preferred_languages = http_accept_language.user_preferred_languages.collect do |pl|
pls = [ pl ]
while pl.match(/^(.*)-[^-]+$/)
end.flatten
end
- request.compatible_language_from(locales) || I18n.default_locale
+ http_accept_language.compatible_language_from(locales) || I18n.default_locale
end
helper_method :select_locale
end
# ask nominatim
- response = fetch_xml("#{NOMINATIM_URL}search?format=xml&q=#{escape_query(query)}#{viewbox}#{exclude}&accept-language=#{request.user_preferred_languages.join(',')}")
+ response = fetch_xml("#{NOMINATIM_URL}search?format=xml&q=#{escape_query(query)}#{viewbox}#{exclude}&accept-language=#{http_accept_language.user_preferred_languages.join(',')}")
# create result array
@results = Array.new
@results = Array.new
# ask nominatim
- response = fetch_xml("#{NOMINATIM_URL}reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{request.user_preferred_languages.join(',')}")
+ response = fetch_xml("#{NOMINATIM_URL}reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{http_accept_language.user_preferred_languages.join(',')}")
# parse the response
response.elements.each("reversegeocode/result") do |result|
@user.data_public = true
@user.description = "" if @user.description.nil?
@user.creation_ip = request.remote_ip
- @user.languages = request.user_preferred_languages
+ @user.languages = http_accept_language.user_preferred_languages
@user.terms_agreed = Time.now.getutc
@user.terms_seen = true
@user.openid_url = nil if @user.openid_url and @user.openid_url.empty?
# https://github.com/iain/http_accept_language/pull/6
#
module HttpAcceptLanguage
- def compatible_language_from(available_languages)
- user_preferred_languages.find do |x|
- available_languages.find { |y| y.to_s == x.to_s } ||
- available_languages.find { |y| y.to_s =~ /^#{Regexp.escape(x.to_s)}-/ }
+ class Parser
+ def compatible_language_from(available_languages)
+ user_preferred_languages.find do |x|
+ available_languages.find { |y| y.to_s == x.to_s } ||
+ available_languages.find { |y| y.to_s =~ /^#{Regexp.escape(x.to_s)}-/ }
+ end
end
end
end
def self.describe_location(lat, lon, zoom = nil, language = nil)
zoom = zoom || 14
- language = language || request.user_preferred_languages.join(',')
+ language = language || http_accept_language.user_preferred_languages.join(',')
Rails.cache.fetch "/nominatim/location/#{lat}/#{lon}/#{zoom}/#{language}" do
url = "http://nominatim.openstreetmap.org/reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{language}"