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.
- data/{README.MD → README.md} +1 -1
- data/lib/fb-localizer.rb +4 -4
- data/lib/fb-localizer/railtie.rb +18 -12
- data/lib/fb-localizer/version.rb +1 -1
- data/pkg/fb-localizer-0.1.0.gem +0 -0
- metadata +6 -5
data/{README.MD → README.md}
RENAMED
data/lib/fb-localizer.rb
CHANGED
@@ -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
|
7
|
+
ruby_locale ||= I18n.locale
|
8
8
|
fb_candidate_locales = FbLocalizer::FbLocalizerHelpers::FB_LOCALES.select{ |l| l.match(/^#{ruby_locale}/)}
|
9
|
-
if
|
10
|
-
|
9
|
+
if fb_candidate_locales.any?
|
10
|
+
fb_candidate_locales[0]
|
11
11
|
else
|
12
|
-
|
12
|
+
"en_US"
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
data/lib/fb-localizer/railtie.rb
CHANGED
@@ -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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
data/lib/fb-localizer/version.rb
CHANGED
Binary file
|
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:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
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-
|
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.
|
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
|