fb-localizer 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/.travis.yml +6 -0
- data/Gemfile.lock +7 -6
- data/README.md +29 -0
- data/fb-localizer.gemspec +1 -1
- data/lib/fb-localizer.rb +14 -11
- data/lib/fb-localizer/railtie.rb +24 -15
- data/lib/fb-localizer/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/testapp/Gemfile.lock +1 -1
- metadata +11 -11
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fb-localizer (0.
|
4
|
+
fb-localizer (0.2.0)
|
5
5
|
i18n
|
6
|
-
libxml-ruby
|
6
|
+
libxml-ruby
|
7
7
|
rails
|
8
8
|
|
9
9
|
GEM
|
@@ -36,20 +36,20 @@ GEM
|
|
36
36
|
activemodel (= 3.0.5)
|
37
37
|
activesupport (= 3.0.5)
|
38
38
|
activesupport (3.0.5)
|
39
|
-
arel (2.0.
|
39
|
+
arel (2.0.10)
|
40
40
|
builder (2.1.2)
|
41
41
|
diff-lcs (1.1.2)
|
42
42
|
erubis (2.6.6)
|
43
43
|
abstract (>= 1.0.0)
|
44
44
|
i18n (0.5.0)
|
45
|
-
libxml-ruby (
|
45
|
+
libxml-ruby (2.2.2)
|
46
46
|
mail (2.2.19)
|
47
47
|
activesupport (>= 2.3.6)
|
48
48
|
i18n (>= 0.4.0)
|
49
49
|
mime-types (~> 1.16)
|
50
50
|
treetop (~> 1.4.8)
|
51
51
|
mime-types (1.16)
|
52
|
-
polyglot (0.3.
|
52
|
+
polyglot (0.3.2)
|
53
53
|
rack (1.2.2)
|
54
54
|
rack-mount (0.6.14)
|
55
55
|
rack (>= 1.0.0)
|
@@ -86,7 +86,8 @@ GEM
|
|
86
86
|
sqlite3-ruby (1.3.3)
|
87
87
|
sqlite3 (>= 1.3.3)
|
88
88
|
thor (0.14.6)
|
89
|
-
treetop (1.4.
|
89
|
+
treetop (1.4.10)
|
90
|
+
polyglot
|
90
91
|
polyglot (>= 0.3.1)
|
91
92
|
tzinfo (0.3.25)
|
92
93
|
|
data/README.md
CHANGED
@@ -13,6 +13,35 @@ So, if we want to add a localized "I like it" button into our web page, we need
|
|
13
13
|
Note: a more complex algorithm on planning which is the nearest locale
|
14
14
|
is planned.
|
15
15
|
|
16
|
+
Priority locales
|
17
|
+
----------------
|
18
|
+
|
19
|
+
FB-Localizer has, from version 0.1.3, the ability to allow the user to
|
20
|
+
set priorities to certain locales.
|
21
|
+
|
22
|
+
If you try to convert "en" (for English) to a Facebook-compatible locale, you will find out that many are available: Pirate, Upside down, United States, and Great Britain. With this priority-locales feature you can indicate FB-Localizer to, in case of having English ("en") to translate, use directly, for example, the English's Great Britain locale.
|
23
|
+
|
24
|
+
Just create an initializer in app/initializers/, and set something like:
|
25
|
+
|
26
|
+
FbLocalizer.configure do |config|
|
27
|
+
config.priorized = { :en => "en_GB" }
|
28
|
+
end
|
29
|
+
|
30
|
+
The format of the priorized locales is a hash. For each record in the hash,
|
31
|
+
|
32
|
+
* The key is the symbol for the locale, e.g :en or :es
|
33
|
+
* The value is your priorized Facebook locale for it, e.g. "en_US" for :en or "es_ES" for :es
|
34
|
+
|
35
|
+
Nevertheless, FB-Localizer itself has default locales for a ruby locale. The complete list is:
|
36
|
+
|
37
|
+
* United States' english
|
38
|
+
* Spain's spanish
|
39
|
+
* Portugal's portuguese
|
40
|
+
* Simplified chinese
|
41
|
+
|
42
|
+
The complete list of Facebook locales is in a XML provided by Facebook
|
43
|
+
itself: [complete list of Facebook locales](http://www.facebook.com/translations/FacebookLocales.xml)
|
44
|
+
|
16
45
|
Usage
|
17
46
|
-----
|
18
47
|
|
data/fb-localizer.gemspec
CHANGED
@@ -24,5 +24,5 @@ nearest Facebook's locale. This way you can localize the "I like it" button on e
|
|
24
24
|
s.add_development_dependency "rspec-rails", "~> 2.5"
|
25
25
|
s.add_dependency "rails"
|
26
26
|
s.add_dependency "i18n"
|
27
|
-
s.add_dependency "libxml-ruby"
|
27
|
+
s.add_dependency "libxml-ruby"
|
28
28
|
end
|
data/lib/fb-localizer.rb
CHANGED
@@ -5,20 +5,23 @@ module FbLocalizer
|
|
5
5
|
DEFAULT_PRIORITIES = { :en => "en_US", :es => "es_ES", :pt => "pt_PT", :zh => "zh_CN" }
|
6
6
|
mattr_accessor :priorized
|
7
7
|
|
8
|
+
@@skip_loading = false
|
9
|
+
@@skip_loading = true if defined?(Rails) && Rails.env.development?
|
10
|
+
mattr_accessor :skip_loading
|
11
|
+
|
8
12
|
module FbLocalizerHelpers
|
9
13
|
def get_fb_locale(ruby_locale = nil)
|
10
|
-
ruby_locale = ruby_locale.to_sym if ruby_locale.is_a? String
|
11
14
|
ruby_locale ||= I18n.locale
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
else
|
21
|
-
|
15
|
+
ruby_locale = ruby_locale.to_sym if ruby_locale.is_a? String
|
16
|
+
|
17
|
+
candidates = FbLocalizer::FbLocalizerHelpers::FB_LOCALES.select{ |l| l.match(/^#{ruby_locale}/)}
|
18
|
+
return "en_US" if candidates.empty? # return American English if no candidates at all
|
19
|
+
|
20
|
+
priorized = FbLocalizer.priorized[ruby_locale] # get priorized locale for that one
|
21
|
+
if priorized && candidates.include?(priorized) # if available, get that one
|
22
|
+
priorized
|
23
|
+
else # if not, just get the first available
|
24
|
+
candidates.first
|
22
25
|
end
|
23
26
|
end
|
24
27
|
end
|
data/lib/fb-localizer/railtie.rb
CHANGED
@@ -7,22 +7,31 @@ require "timeout"
|
|
7
7
|
module FbLocalizer
|
8
8
|
class Railtie < Rails::Railtie
|
9
9
|
initializer "fb-localizer.configure_rails_initialization" do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
10
|
+
def load_defaults
|
11
|
+
FbLocalizer::FbLocalizerHelpers.const_set(:FB_LOCALES, ["en_US","es_ES","ca_ES"])
|
12
|
+
end
|
13
|
+
|
14
|
+
if FbLocalizer.skip_loading
|
15
|
+
puts "FB-Localizer => Skipped, using defaults instead"
|
16
|
+
load_defaults
|
17
|
+
else
|
18
|
+
begin
|
19
|
+
Timeout::timeout(5) do
|
20
|
+
url = "http://www.facebook.com/translations/FacebookLocales.xml"
|
21
|
+
open(url){ |f|
|
22
|
+
xml = f.readlines.join("\n")
|
23
|
+
fb_locales = XML::Parser.string(xml).parse
|
24
|
+
FbLocalizer::FbLocalizerHelpers::FB_LOCALES = []
|
25
|
+
fb_locales.find('//locales/locale/codes/code/standard/representation').each do |node|
|
26
|
+
FbLocalizer::FbLocalizerHelpers::FB_LOCALES << node.content
|
27
|
+
end
|
28
|
+
puts "FB-Localizer => Locales read successfully from <http://www.facebook.com/translations/FacebookLocales.xml>"
|
29
|
+
}
|
30
|
+
end
|
31
|
+
rescue Exception => e
|
32
|
+
puts "FB-Localizer => Exception '#{e}', using defaults instead"
|
33
|
+
load_defaults
|
22
34
|
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"]
|
26
35
|
end
|
27
36
|
end
|
28
37
|
end
|
data/lib/fb-localizer/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/testapp/Gemfile.lock
CHANGED
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: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
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-10-08 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -67,14 +67,12 @@ dependencies:
|
|
67
67
|
requirement: &id004 !ruby/object:Gem::Requirement
|
68
68
|
none: false
|
69
69
|
requirements:
|
70
|
-
- - "
|
70
|
+
- - ">="
|
71
71
|
- !ruby/object:Gem::Version
|
72
|
-
hash:
|
72
|
+
hash: 3
|
73
73
|
segments:
|
74
|
-
-
|
75
|
-
|
76
|
-
- 3
|
77
|
-
version: 1.1.3
|
74
|
+
- 0
|
75
|
+
version: "0"
|
78
76
|
type: :runtime
|
79
77
|
version_requirements: *id004
|
80
78
|
description: |-
|
@@ -90,6 +88,8 @@ extra_rdoc_files: []
|
|
90
88
|
|
91
89
|
files:
|
92
90
|
- .gitignore
|
91
|
+
- .rspec
|
92
|
+
- .travis.yml
|
93
93
|
- Gemfile
|
94
94
|
- Gemfile.lock
|
95
95
|
- README.md
|