fb-localizer 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- NifVal
1
+ FB Localizer
2
2
  ======
3
3
 
4
4
  Description
@@ -4,12 +4,12 @@ require 'i18n'
4
4
  module FbLocalizer
5
5
  module FbLocalizerHelpers
6
6
  def get_fb_locale(ruby_locale = nil)
7
- ruby_locale = ruby_locale || I18n.locale
7
+ ruby_locale ||= I18n.locale
8
8
  fb_candidate_locales = FbLocalizer::FbLocalizerHelpers::FB_LOCALES.select{ |l| l.match(/^#{ruby_locale}/)}
9
- if !fb_candidate_locales.empty?
10
- return fb_candidate_locales[0]
9
+ if fb_candidate_locales.any?
10
+ fb_candidate_locales[0]
11
11
  else
12
- return "en_US"
12
+ "en_US"
13
13
  end
14
14
  end
15
15
  end
@@ -1,23 +1,29 @@
1
1
  require 'rails'
2
2
  require 'fb-localizer'
3
3
  require 'xml'
4
+ require "open-uri"
5
+ require "timeout"
4
6
 
5
7
  module FbLocalizer
6
8
  class Railtie < Rails::Railtie
7
9
  initializer "fb-localizer.configure_rails_initialization" do
8
- # Get locales
9
- url = "www.facebook.com/translations/FacebookLocales.xml"
10
- `wget -qO- #{url} >> tmp.xml`
11
-
12
- # Navigate and get locales
13
- FbLocalizer::FbLocalizerHelpers::FB_LOCALES = []
14
- fb_locales = XML::Document.file("tmp.xml")
15
- fb_locales.find('//locales/locale/codes/code/standard/representation').each do |node|
16
- FbLocalizer::FbLocalizerHelpers::FB_LOCALES << node.content
10
+ begin
11
+ Timeout::timeout(5) do
12
+ url = "http://www.facebook.com/translations/FacebookLocales.xml"
13
+ open(url){ |f|
14
+ xml = f.readlines.join("\n")
15
+ fb_locales = XML::Parser.string(xml).parse
16
+ FbLocalizer::FbLocalizerHelpers::FB_LOCALES = []
17
+ fb_locales.find('//locales/locale/codes/code/standard/representation').each do |node|
18
+ FbLocalizer::FbLocalizerHelpers::FB_LOCALES << node.content
19
+ end
20
+ puts "FB-Localizer => Locales read successfully from <http://www.facebook.com/translations/FacebookLocales.xml>"
21
+ }
22
+ end
23
+ rescue Exception => e
24
+ puts "FB-Localizer => Exception '#{e}', using defaults instead"
25
+ FbLocalizer::FbLocalizerHelpers::FB_LOCALES = ["en_US","es_ES","ca_ES"]
17
26
  end
18
-
19
- # Remove tmp file
20
- `rm tmp.xml`
21
27
  end
22
28
  end
23
29
  end
@@ -1,5 +1,5 @@
1
1
  module Fb
2
2
  module Localizer
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fb-localizer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Albert Bellonch
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-31 00:00:00 +02:00
18
+ date: 2011-04-06 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -89,12 +89,13 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - Gemfile
91
91
  - Gemfile.lock
92
- - README.MD
92
+ - README.md
93
93
  - Rakefile
94
94
  - fb-localizer.gemspec
95
95
  - lib/fb-localizer.rb
96
96
  - lib/fb-localizer/railtie.rb
97
97
  - lib/fb-localizer/version.rb
98
+ - pkg/fb-localizer-0.1.0.gem
98
99
  - spec/helpers/fb-localizer_spec.rb
99
100
  - spec/spec_helper.rb
100
101
  - testapp/.gitignore