lib/fb-localizer/railtie.rb in fb-localizer-0.1.3 vs lib/fb-localizer/railtie.rb in fb-localizer-0.2.0

- old
+ new

@@ -5,25 +5,34 @@ require "timeout" module FbLocalizer class Railtie < Rails::Railtie initializer "fb-localizer.configure_rails_initialization" do - begin - Timeout::timeout(5) do - url = "http://www.facebook.com/translations/FacebookLocales.xml" - open(url){ |f| - xml = f.readlines.join("\n") - fb_locales = XML::Parser.string(xml).parse - FbLocalizer::FbLocalizerHelpers::FB_LOCALES = [] - fb_locales.find('//locales/locale/codes/code/standard/representation').each do |node| - FbLocalizer::FbLocalizerHelpers::FB_LOCALES << node.content - end - puts "FB-Localizer => Locales read successfully from <http://www.facebook.com/translations/FacebookLocales.xml>" - } + def load_defaults + FbLocalizer::FbLocalizerHelpers.const_set(:FB_LOCALES, ["en_US","es_ES","ca_ES"]) + end + + if FbLocalizer.skip_loading + puts "FB-Localizer => Skipped, using defaults instead" + load_defaults + else + begin + Timeout::timeout(5) do + url = "http://www.facebook.com/translations/FacebookLocales.xml" + open(url){ |f| + xml = f.readlines.join("\n") + fb_locales = XML::Parser.string(xml).parse + FbLocalizer::FbLocalizerHelpers::FB_LOCALES = [] + fb_locales.find('//locales/locale/codes/code/standard/representation').each do |node| + FbLocalizer::FbLocalizerHelpers::FB_LOCALES << node.content + end + puts "FB-Localizer => Locales read successfully from <http://www.facebook.com/translations/FacebookLocales.xml>" + } + end + rescue Exception => e + puts "FB-Localizer => Exception '#{e}', using defaults instead" + load_defaults end - rescue Exception => e - puts "FB-Localizer => Exception '#{e}', using defaults instead" - FbLocalizer::FbLocalizerHelpers::FB_LOCALES = ["en_US","es_ES","ca_ES"] end end end end