diff options
author | Robin Houston <robin.houston@gmail.com> | 2012-06-23 09:33:42 +0100 |
---|---|---|
committer | Robin Houston <robin.houston@gmail.com> | 2012-06-23 09:33:42 +0100 |
commit | db1a388f0a7b37cc0ceb3ca07b995b34dabdba58 (patch) | |
tree | e34df5ae0dacdbf6c3b77542b22f2d9e3799d322 /lib | |
parent | a7cc84b9b2b430644fe23e6328d7ab289e7abf0a (diff) | |
parent | 7d0fea4b38c214a67b2fc4b56aa670e02a3cda61 (diff) |
Merge branch 'develop' of github.com:sebbacon/alaveteli into develop
Conflicts:
Gemfile.lock
script/handle-mail-replies
script/handle-mail-replies.rb
spec/controllers/request_controller_spec.rb
Diffstat (limited to 'lib')
-rw-r--r-- | lib/languages.rb | 5 | ||||
-rw-r--r-- | lib/quiet_opener.rb | 23 | ||||
-rw-r--r-- | lib/routing_filters.rb | 17 | ||||
-rw-r--r-- | lib/tasks/gettext.rake | 4 |
4 files changed, 37 insertions, 12 deletions
diff --git a/lib/languages.rb b/lib/languages.rb index 474c0e0cb..42231ef56 100644 --- a/lib/languages.rb +++ b/lib/languages.rb @@ -187,8 +187,9 @@ class LanguageNames 'za' => 'Saɯ cueŋƅ', 'zu' => 'isiZulu' } - - return language_names[locale] + locale = locale.sub("_", "-") # normalize + main_part = I18n::Locale::Tag::Simple.tag(locale).subtags[0] + return language_names[main_part] end end diff --git a/lib/quiet_opener.rb b/lib/quiet_opener.rb index a077ca323..8cedad250 100644 --- a/lib/quiet_opener.rb +++ b/lib/quiet_opener.rb @@ -1,11 +1,12 @@ require 'open-uri' require 'net-purge' +require 'net/http/local' def quietly_try_to_open(url) begin result = open(url).read.strip rescue OpenURI::HTTPError, SocketError, Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH - logger.warn("Unable to open third-party URL #{url}") + Rails.logger.warn("Unable to open third-party URL #{url}") result = "" end return result @@ -15,19 +16,21 @@ def quietly_try_to_purge(host, url) begin result = "" result_body = "" - Net::HTTP.start(host) {|http| - request = Net::HTTP::Purge.new(url) - response = http.request(request) - result = response.code - result_body = response.body - } + Net::HTTP.bind '127.0.0.1' do + Net::HTTP.start(host) {|http| + request = Net::HTTP::Purge.new(url) + response = http.request(request) + result = response.code + result_body = response.body + } + end rescue OpenURI::HTTPError, SocketError, Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH - logger.warn("Unable to reach host #{host}") + Rails.logger.warn("PURGE: Unable to reach host #{host}") end if result == "200" - logger.info("Purged URL #{url} at #{host}: #{result}") + Rails.logger.debug("PURGE: Purged URL #{url} at #{host}: #{result}") else - logger.warn("Unable to purge URL #{url} at #{host}: status #{result}") + Rails.logger.warn("PURGE: Unable to purge URL #{url} at #{host}: status #{result}") end return result end diff --git a/lib/routing_filters.rb b/lib/routing_filters.rb index cdb58e7c1..32dafc651 100644 --- a/lib/routing_filters.rb +++ b/lib/routing_filters.rb @@ -5,5 +5,22 @@ module RoutingFilter def prepend_locale?(locale) locale && I18n.available_locales.length > 1 && (self.class.include_default_locale? || !default_locale?(locale)) end + # And override the generation logic to use FastGettext.locale + # rather than I18n.locale (the latter is what rails uses + # internally and may look like `en_US`, whereas the latter is + # was FastGettext and other POSIX-based systems use, and will + # look like `en_US` + def around_generate(*args, &block) + params = args.extract_options! # this is because we might get a call like forum_topics_path(forum, topic, :locale => :en) + + locale = params.delete(:locale) # extract the passed :locale option + locale = FastGettext.locale if locale.nil? # default to I18n.locale when locale is nil (could also be false) + locale = nil unless valid_locale?(locale) # reset to no locale when locale is not valid + args << params + + yield.tap do |result| + prepend_segment!(result, locale) if prepend_locale?(locale) + end + end end end diff --git a/lib/tasks/gettext.rake b/lib/tasks/gettext.rake index 56e9f6df6..787b4029f 100644 --- a/lib/tasks/gettext.rake +++ b/lib/tasks/gettext.rake @@ -1,3 +1,7 @@ +# 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 "Update pot file only, without fuzzy guesses (these are done by Transifex)" |