aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/configuration.rb111
-rw-r--r--lib/google_translate.rb18
-rw-r--r--lib/i18n_fixes.rb11
-rw-r--r--lib/quiet_opener.rb12
-rw-r--r--lib/tasks/gettext.rake4
5 files changed, 74 insertions, 82 deletions
diff --git a/lib/configuration.rb b/lib/configuration.rb
index cc85f0db3..88890856b 100644
--- a/lib/configuration.rb
+++ b/lib/configuration.rb
@@ -13,60 +13,63 @@ MySociety::Config.load_default
# TODO: Make this return different values depending on the current rails environment
module AlaveteliConfiguration
- DEFAULTS = {
- :ADMIN_PASSWORD => '',
- :ADMIN_USERNAME => '',
- :AVAILABLE_LOCALES => '',
- :BLACKHOLE_PREFIX => 'do-not-reply-to-this-address',
- :BLOG_FEED => '',
- :CONTACT_EMAIL => 'contact@localhost',
- :CONTACT_NAME => 'Alaveteli',
- :COOKIE_STORE_SESSION_SECRET => 'this default is insecure as code is open source, please override for live sites in config/general; this will do for local development',
- :DEBUG_RECORD_MEMORY => false,
- :DEFAULT_LOCALE => '',
- :DISABLE_EMERGENCY_USER => false,
- :DOMAIN => 'localhost:3000',
- :EXCEPTION_NOTIFICATIONS_FROM => '',
- :EXCEPTION_NOTIFICATIONS_TO => '',
- :FORCE_REGISTRATION_ON_NEW_REQUEST => false,
- :FORCE_SSL => true,
- :FORWARD_NONBOUNCE_RESPONSES_TO => 'user-support@localhost',
- :FRONTPAGE_PUBLICBODY_EXAMPLES => '',
- :GA_CODE => '',
- :GAZE_URL => '',
- :HTML_TO_PDF_COMMAND => '',
- :INCLUDE_DEFAULT_LOCALE_IN_URLS => true,
- :INCOMING_EMAIL_DOMAIN => 'localhost',
- :INCOMING_EMAIL_PREFIX => '',
- :INCOMING_EMAIL_SECRET => 'dummysecret',
- :ISO_COUNTRY_CODE => 'GB',
- :MAX_REQUESTS_PER_USER_PER_DAY => '',
- :MTA_LOG_TYPE => 'exim',
- :NEW_RESPONSE_REMINDER_AFTER_DAYS => [3, 10, 24],
- :OVERRIDE_ALL_PUBLIC_BODY_REQUEST_EMAILS => '',
- :RAW_EMAILS_LOCATION => 'files/raw_emails',
- :READ_ONLY => '',
- :RECAPTCHA_PRIVATE_KEY => 'x',
- :RECAPTCHA_PUBLIC_KEY => 'x',
- :REPLY_LATE_AFTER_DAYS => 20,
- :REPLY_VERY_LATE_AFTER_DAYS => 40,
- :SITE_NAME => 'Alaveteli',
- :SKIP_ADMIN_AUTH => false,
- :SPECIAL_REPLY_VERY_LATE_AFTER_DAYS => 60,
- :THEME_BRANCH => false,
- :THEME_URL => "",
- :THEME_URLS => [],
- :TIME_ZONE => "UTC",
- :TRACK_SENDER_EMAIL => 'contact@localhost',
- :TRACK_SENDER_NAME => 'Alaveteli',
- :TWITTER_USERNAME => '',
- :TWITTER_WIDGET_ID => false,
- :USE_DEFAULT_BROWSER_LANGUAGE => true,
- :USE_GHOSTSCRIPT_COMPRESSION => false,
- :UTILITY_SEARCH_PATH => ["/usr/bin", "/usr/local/bin"],
- :VARNISH_HOST => '',
- :WORKING_OR_CALENDAR_DAYS => 'working',
- }
+ if !const_defined?(:DEFAULTS)
+
+ DEFAULTS = {
+ :ADMIN_PASSWORD => '',
+ :ADMIN_USERNAME => '',
+ :AVAILABLE_LOCALES => '',
+ :BLACKHOLE_PREFIX => 'do-not-reply-to-this-address',
+ :BLOG_FEED => '',
+ :CONTACT_EMAIL => 'contact@localhost',
+ :CONTACT_NAME => 'Alaveteli',
+ :COOKIE_STORE_SESSION_SECRET => 'this default is insecure as code is open source, please override for live sites in config/general; this will do for local development',
+ :DEBUG_RECORD_MEMORY => false,
+ :DEFAULT_LOCALE => '',
+ :DISABLE_EMERGENCY_USER => false,
+ :DOMAIN => 'localhost:3000',
+ :EXCEPTION_NOTIFICATIONS_FROM => '',
+ :EXCEPTION_NOTIFICATIONS_TO => '',
+ :FORCE_REGISTRATION_ON_NEW_REQUEST => false,
+ :FORCE_SSL => true,
+ :FORWARD_NONBOUNCE_RESPONSES_TO => 'user-support@localhost',
+ :FRONTPAGE_PUBLICBODY_EXAMPLES => '',
+ :GA_CODE => '',
+ :GAZE_URL => '',
+ :HTML_TO_PDF_COMMAND => '',
+ :INCLUDE_DEFAULT_LOCALE_IN_URLS => true,
+ :INCOMING_EMAIL_DOMAIN => 'localhost',
+ :INCOMING_EMAIL_PREFIX => '',
+ :INCOMING_EMAIL_SECRET => 'dummysecret',
+ :ISO_COUNTRY_CODE => 'GB',
+ :MAX_REQUESTS_PER_USER_PER_DAY => '',
+ :MTA_LOG_TYPE => 'exim',
+ :NEW_RESPONSE_REMINDER_AFTER_DAYS => [3, 10, 24],
+ :OVERRIDE_ALL_PUBLIC_BODY_REQUEST_EMAILS => '',
+ :RAW_EMAILS_LOCATION => 'files/raw_emails',
+ :READ_ONLY => '',
+ :RECAPTCHA_PRIVATE_KEY => 'x',
+ :RECAPTCHA_PUBLIC_KEY => 'x',
+ :REPLY_LATE_AFTER_DAYS => 20,
+ :REPLY_VERY_LATE_AFTER_DAYS => 40,
+ :SITE_NAME => 'Alaveteli',
+ :SKIP_ADMIN_AUTH => false,
+ :SPECIAL_REPLY_VERY_LATE_AFTER_DAYS => 60,
+ :THEME_BRANCH => false,
+ :THEME_URL => "",
+ :THEME_URLS => [],
+ :TIME_ZONE => "UTC",
+ :TRACK_SENDER_EMAIL => 'contact@localhost',
+ :TRACK_SENDER_NAME => 'Alaveteli',
+ :TWITTER_USERNAME => '',
+ :TWITTER_WIDGET_ID => false,
+ :USE_DEFAULT_BROWSER_LANGUAGE => true,
+ :USE_GHOSTSCRIPT_COMPRESSION => false,
+ :UTILITY_SEARCH_PATH => ["/usr/bin", "/usr/local/bin"],
+ :VARNISH_HOST => '',
+ :WORKING_OR_CALENDAR_DAYS => 'working',
+ }
+ end
def AlaveteliConfiguration.method_missing(name)
key = name.to_s.upcase
diff --git a/lib/google_translate.rb b/lib/google_translate.rb
deleted file mode 100644
index 369e1de3b..000000000
--- a/lib/google_translate.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require 'rubygems'
-require 'net/http'
-require 'open-uri'
-require 'cgi'
-require 'json'
-
-def detect_language(request, translate_string)
- google_api_key = ''
- user_ip = URI.encode(request.env['REMOTE_ADDR'])
- translate_string = URI.encode(translate_string)
- url = "http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q=#{translate_string}&userip=#{user_ip}"
- if google_api_key != ''
- url += "&key=#{google_api_key}"
- end
- response = Net::HTTP.get_response(URI.parse(url))
- result = JSON.parse(response.body)
- result['responseData']['language']
-end
diff --git a/lib/i18n_fixes.rb b/lib/i18n_fixes.rb
index a85faddcb..82d1b2c3a 100644
--- a/lib/i18n_fixes.rb
+++ b/lib/i18n_fixes.rb
@@ -14,6 +14,17 @@ def _(key, options = {})
gettext_interpolate(translation, options)
end
+def n_(*keys)
+ # The last parameter should be the values to do the interpolation with
+ if keys.count > 3
+ options = keys.pop
+ else
+ options = {}
+ end
+ translation = FastGettext.n_(*keys).html_safe
+ gettext_interpolate(translation, options)
+end
+
MATCH = /\{\{([^\}]+)\}\}/
def gettext_interpolate(string, values)
diff --git a/lib/quiet_opener.rb b/lib/quiet_opener.rb
index bde645d0b..ae6605c43 100644
--- a/lib/quiet_opener.rb
+++ b/lib/quiet_opener.rb
@@ -3,7 +3,7 @@ require 'net-purge'
require 'net/http/local'
def quietly_try_to_open(url)
- begin
+ begin
result = open(url).read.strip
rescue OpenURI::HTTPError, SocketError, Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET
Rails.logger.warn("Unable to open third-party URL #{url}")
@@ -11,12 +11,12 @@ def quietly_try_to_open(url)
end
return result
end
-
+
def quietly_try_to_purge(host, url)
- begin
+ begin
result = ""
result_body = ""
- Net::HTTP.bind '127.0.0.1' do
+ Net::HTTP.bind '127.0.0.1' do
Net::HTTP.start(host) {|http|
request = Net::HTTP::Purge.new(url)
response = http.request(request)
@@ -24,7 +24,7 @@ def quietly_try_to_purge(host, url)
result_body = response.body
}
end
- rescue OpenURI::HTTPError, SocketError, Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET
+ rescue OpenURI::HTTPError, SocketError, Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET, Errno::ENETUNREACH
Rails.logger.warn("PURGE: Unable to reach host #{host}")
end
if result == "200"
@@ -34,4 +34,4 @@ def quietly_try_to_purge(host, url)
end
return result
end
-
+
diff --git a/lib/tasks/gettext.rake b/lib/tasks/gettext.rake
index c73c2584e..ace7205ae 100644
--- a/lib/tasks/gettext.rake
+++ b/lib/tasks/gettext.rake
@@ -1,7 +1,3 @@
-# Rails won't automatically load rakefiles from gems - see
-# http://stackoverflow.com/questions/1878640/including-rake-tasks-in-gems
-Dir["#{Gem.searcher.find('gettext_i18n_rails').full_gem_path}/lib/tasks/**/*.rake"].each { |ext| load ext }
-
namespace :gettext do
desc 'Rewrite .po files into a consistent msgmerge format'