From 50eb7689c7d6339f8a28350d9ed3776e2626924a Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Tue, 12 Jun 2012 13:47:57 +0100 Subject: Fall back to "parent" locale names when deciding the localised language name. Fixes #503 --- lib/languages.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/languages.rb b/lib/languages.rb index 474c0e0cb..4d355ab59 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("_", "-") + main_part = I18n::Locale::Tag::Simple.tag(locale).subtags[0] + return language_names[main_part] end end -- cgit v1.2.3 From 8f0b7b6f86dc60a51d4ffab2a5fd627fa3499b8a Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 13 Jun 2012 14:07:58 +0100 Subject: Fix it so we can correctly use and display locales that contain an underscore (e.g. `hu_HU`): * Use the latest version of `gettext_i18n_rails` (including fix to make it work in Railes 2.x) * Use a backend that falls back to, for example, `hu` from `hu_HU` (so we can use any underlying Rails l10n) * Normalize the underscore to a hyphen when working out which languages to display in the language switcher Fixes #503 (and see there for more discussion) --- lib/languages.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/languages.rb b/lib/languages.rb index 4d355ab59..42231ef56 100644 --- a/lib/languages.rb +++ b/lib/languages.rb @@ -187,7 +187,7 @@ class LanguageNames 'za' => 'Saɯ cueŋƅ', 'zu' => 'isiZulu' } - locale = locale.sub("_", "-") + locale = locale.sub("_", "-") # normalize main_part = I18n::Locale::Tag::Simple.tag(locale).subtags[0] return language_names[main_part] end -- cgit v1.2.3 From 7bcaaf2b8e3e81ff963b5cd1b1586d727e92f51e Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Thu, 14 Jun 2012 13:06:28 +0100 Subject: Upgrade to latest gettext_i18n_rails. As we are now using a gem, we also need to explicitly include the rake tasts from that gem. --- lib/tasks/gettext.rake | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') 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)" -- cgit v1.2.3 From b30554dc4fcdeeb42d827ead474b1e135bc877e8 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Thu, 14 Jun 2012 13:47:47 +0100 Subject: Ensure we generate URLs containing the current locale, even if the locale contains an underscore. Includes a bonus test to ensure that locales with unknown territories fall back to known languages. --- lib/routing_filters.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib') 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 -- cgit v1.2.3 From eb9595e6603580a0ba413379b4cb133cba80a4a3 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 20 Jun 2012 08:41:40 +0100 Subject: Use explicit `Rails.logger` (as we're not inheriting from ActiveRecord) --- lib/quiet_opener.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/quiet_opener.rb b/lib/quiet_opener.rb index a077ca323..11adfe402 100644 --- a/lib/quiet_opener.rb +++ b/lib/quiet_opener.rb @@ -5,7 +5,7 @@ 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 @@ -22,12 +22,12 @@ def quietly_try_to_purge(host, url) result_body = response.body } rescue OpenURI::HTTPError, SocketError, Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH - logger.warn("Unable to reach host #{host}") + Rails.logger.warn("Unable to reach host #{host}") end if result == "200" - logger.info("Purged URL #{url} at #{host}: #{result}") + Rails.logger.info("Purged URL #{url} at #{host}: #{result}") else - logger.warn("Unable to purge URL #{url} at #{host}: status #{result}") + Rails.logger.warn("Unable to purge URL #{url} at #{host}: status #{result}") end return result end -- cgit v1.2.3 From b94559f7966b9db71fae3a9d2bbcac5216712699 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 20 Jun 2012 09:16:09 +0100 Subject: Bind PURGE requests to localhost --- lib/quiet_opener.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/quiet_opener.rb b/lib/quiet_opener.rb index 11adfe402..2f78f76ad 100644 --- a/lib/quiet_opener.rb +++ b/lib/quiet_opener.rb @@ -15,12 +15,14 @@ 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 Rails.logger.warn("Unable to reach host #{host}") end -- cgit v1.2.3 From 76839f2090b7f1ca943439ddd794728518eda46a Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 20 Jun 2012 09:46:03 +0100 Subject: Increase the time a page is cached for sites that are using Varnish. Relatedly, document the consequences of getting the Varnish config wrong; and make it easier to grep for problems with Varnish in the log. --- lib/quiet_opener.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/quiet_opener.rb b/lib/quiet_opener.rb index 2f78f76ad..f313b303c 100644 --- a/lib/quiet_opener.rb +++ b/lib/quiet_opener.rb @@ -24,12 +24,12 @@ def quietly_try_to_purge(host, url) } end rescue OpenURI::HTTPError, SocketError, Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH - Rails.logger.warn("Unable to reach host #{host}") + Rails.logger.warn("PURGE: Unable to reach host #{host}") end if result == "200" - Rails.logger.info("Purged URL #{url} at #{host}: #{result}") + Rails.logger.info("PURGE: Purged URL #{url} at #{host}: #{result}") else - Rails.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 -- cgit v1.2.3 From 9f578d781b7e575d89432facccfc5b41b4664297 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 20 Jun 2012 09:59:07 +0100 Subject: Make successful PURGEs log at debug level to reduce unecessary noise at default level (info) --- lib/quiet_opener.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/quiet_opener.rb b/lib/quiet_opener.rb index f313b303c..cb8cf0619 100644 --- a/lib/quiet_opener.rb +++ b/lib/quiet_opener.rb @@ -27,7 +27,7 @@ def quietly_try_to_purge(host, url) Rails.logger.warn("PURGE: Unable to reach host #{host}") end if result == "200" - Rails.logger.info("PURGE: Purged URL #{url} at #{host}: #{result}") + Rails.logger.debug("PURGE: Purged URL #{url} at #{host}: #{result}") else Rails.logger.warn("PURGE: Unable to purge URL #{url} at #{host}: status #{result}") end -- cgit v1.2.3