i18n_data 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,5 +1,6 @@
1
1
  source :rubygems
2
2
  gemspec
3
3
 
4
+ gem "bump"
4
5
  gem "rake"
5
6
  gem "rspec", "~>2"
data/Gemfile.lock CHANGED
@@ -1,26 +1,28 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- i18n_data (0.3.3)
4
+ i18n_data (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
+ bump (0.3.9)
9
10
  diff-lcs (1.1.3)
10
- rake (0.9.2.2)
11
- rspec (2.8.0)
12
- rspec-core (~> 2.8.0)
13
- rspec-expectations (~> 2.8.0)
14
- rspec-mocks (~> 2.8.0)
15
- rspec-core (2.8.0)
16
- rspec-expectations (2.8.0)
17
- diff-lcs (~> 1.1.2)
18
- rspec-mocks (2.8.0)
11
+ rake (10.0.3)
12
+ rspec (2.12.0)
13
+ rspec-core (~> 2.12.0)
14
+ rspec-expectations (~> 2.12.0)
15
+ rspec-mocks (~> 2.12.0)
16
+ rspec-core (2.12.2)
17
+ rspec-expectations (2.12.1)
18
+ diff-lcs (~> 1.1.3)
19
+ rspec-mocks (2.12.2)
19
20
 
20
21
  PLATFORMS
21
22
  ruby
22
23
 
23
24
  DEPENDENCIES
25
+ bump
24
26
  i18n_data!
25
27
  rake
26
28
  rspec (~> 2)
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'bump/tasks'
2
3
  $LOAD_PATH << "lib"
3
4
  require 'i18n_data'
4
5
 
@@ -74,20 +75,3 @@ task :write_cache_for_file_data_provider do
74
75
  puts "writing new caches, this can take a few minutes..."
75
76
  I18nData::FileDataProvider.write_cache(I18nData::LiveDataProvider)
76
77
  end
77
-
78
- # extracted from https://github.com/grosser/project_template
79
- rule /^version:bump:.*/ do |t|
80
- sh "git status | grep 'nothing to commit'" # ensure we are not dirty
81
- index = ['major', 'minor','patch'].index(t.name.split(':').last)
82
- file = 'lib/i18n_data/version.rb'
83
-
84
- version_file = File.read(file)
85
- old_version, *version_parts = version_file.match(/(\d+)\.(\d+)\.(\d+)/).to_a
86
- version_parts[index] = version_parts[index].to_i + 1
87
- version_parts[2] = 0 if index < 2 # remove patch for minor
88
- version_parts[1] = 0 if index < 1 # remove minor for major
89
- new_version = version_parts * '.'
90
- File.open(file,'w'){|f| f.write(version_file.sub(old_version, new_version)) }
91
-
92
- sh "bundle && git add #{file} Gemfile.lock && git commit -m 'bump version to #{new_version}'"
93
- end
data/Readme.md CHANGED
@@ -57,5 +57,5 @@ Author
57
57
  [Michael Grosser](http://grosser.it)<br/>
58
58
  michael@grosser.it<br/>
59
59
  License: MIT<br/>
60
- [![Build Status](https://secure.travis-ci.org/grosser/i18n_data.png)](http://travis-ci.org/grosser/i18n_data)
60
+ [![Build Status](https://travis-ci.org/grosser/i18n_data.png)](https://travis-ci.org/grosser/i18n_data)
61
61
 
@@ -0,0 +1,20 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDMjCCAhqgAwIBAgIBADANBgkqhkiG9w0BAQUFADA/MRAwDgYDVQQDDAdtaWNo
3
+ YWVsMRcwFQYKCZImiZPyLGQBGRYHZ3Jvc3NlcjESMBAGCgmSJomT8ixkARkWAml0
4
+ MB4XDTEzMDIwMzE4MTMxMVoXDTE0MDIwMzE4MTMxMVowPzEQMA4GA1UEAwwHbWlj
5
+ aGFlbDEXMBUGCgmSJomT8ixkARkWB2dyb3NzZXIxEjAQBgoJkiaJk/IsZAEZFgJp
6
+ dDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMorXo/hgbUq97+kII9H
7
+ MsQcLdC/7wQ1ZP2OshVHPkeP0qH8MBHGg6eYisOX2ubNagF9YTCZWnhrdKrwpLOO
8
+ cPLaZbjUjljJ3cQR3B8Yn1veV5IhG86QseTBjymzJWsLpqJ1UZGpfB9tXcsFtuxO
9
+ 6vHvcIHdzvc/OUkICttLbH+1qb6rsHUceqh+JrH4GrsJ5H4hAfIdyS2XMK7YRKbh
10
+ h+IBu6dFWJJByzFsYmV1PDXln3UBmgAt65cmCu4qPfThioCGDzbSJrGDGLmw/pFX
11
+ FPpVCm1zgYSb1v6Qnf3cgXa2f2wYGm17+zAVyIDpwryFru9yF/jJxE38z/DRsd9R
12
+ /88CAwEAAaM5MDcwCQYDVR0TBAIwADAdBgNVHQ4EFgQUsiNnXHtKeMYYcr4yJVmQ
13
+ WONL+IwwCwYDVR0PBAQDAgSwMA0GCSqGSIb3DQEBBQUAA4IBAQAlyN7kKo/NQCQ0
14
+ AOzZLZ3WAePvStkCFIJ53tsv5Kyo4pMAllv+BgPzzBt7qi605mFSL6zBd9uLou+W
15
+ Co3s48p1dy7CjjAfVQdmVNHF3MwXtfC2OEyvSQPi4xKR8iba8wa3xp9LVo1PuLpw
16
+ /6DsrChWw74HfsJN6qJOK684hJeT8lBYAUfiC3wD0owoPSg+XtyAAddisR+KV5Y1
17
+ NmVHuLtQcNTZy+gRht3ahJRMuC6QyLmkTsf+6MaenwAMkAgHdswGsJztOnNnBa3F
18
+ y0kCSWmK6D+x/SbfS6r7Ke07MRqziJdB9GuE1+0cIRuFh8EQ+LN6HXCKM5pon/GU
19
+ ycwMXfl0
20
+ -----END CERTIFICATE-----
data/i18n_data.gemspec CHANGED
@@ -6,7 +6,9 @@ Gem::Specification.new name, I18nData::VERSION do |s|
6
6
  s.summary = "country/language names and 2-letter-code pairs, in 85 languages"
7
7
  s.authors = ["Michael Grosser"]
8
8
  s.email = "michael@grosser.it"
9
- s.homepage = "http://github.com/grosser/#{name}"
9
+ s.homepage = "https://github.com/grosser/#{name}"
10
10
  s.files = `git ls-files`.split("\n")
11
11
  s.license = "MIT"
12
+ s.signing_key = File.expand_path("~/.ssh/gem-private_key.pem")
13
+ s.cert_chain = ["gem-public_cert.pem"]
12
14
  end
@@ -1,3 +1,3 @@
1
1
  module I18nData
2
- VERSION = Version = "0.3.3"
2
+ VERSION = Version = "0.4.0"
3
3
  end
data/lib/i18n_data.rb CHANGED
@@ -1,71 +1,85 @@
1
1
  require 'i18n_data/version'
2
2
 
3
3
  module I18nData
4
- extend self
5
-
6
- def languages(language_code='EN')
7
- data_provider.codes(:languages, normal_to_region_code(language_code.to_s.upcase))
4
+ class NoTranslationAvailable < Exception
5
+ def to_s
6
+ "NoTranslationAvailable -- #{super}"
7
+ end
8
8
  end
9
9
 
10
- def countries(language_code='EN')
11
- data_provider.codes(:countries, normal_to_region_code(language_code.to_s.upcase))
12
- end
10
+ class << self
11
+ def languages(language_code='EN')
12
+ fetch :languages, language_code do
13
+ data_provider.codes(:languages, normal_to_region_code(language_code.to_s.upcase))
14
+ end
15
+ end
13
16
 
14
- def country_code(name)
15
- recognise_code(:countries, name)
16
- end
17
+ def countries(language_code='EN')
18
+ fetch :countries, language_code do
19
+ data_provider.codes(:countries, normal_to_region_code(language_code.to_s.upcase))
20
+ end
21
+ end
17
22
 
18
- def language_code(name)
19
- recognise_code(:languages, name)
20
- end
23
+ def country_code(name)
24
+ recognise_code(:countries, name)
25
+ end
21
26
 
22
- def data_provider
23
- if @data_provider
24
- @data_provider
25
- else
26
- require 'i18n_data/file_data_provider'
27
- FileDataProvider
27
+ def language_code(name)
28
+ recognise_code(:languages, name)
28
29
  end
29
- end
30
30
 
31
- def data_provider=(provider)
32
- @data_provider = provider
33
- end
31
+ def data_provider
32
+ if @data_provider
33
+ @data_provider
34
+ else
35
+ require 'i18n_data/file_data_provider'
36
+ FileDataProvider
37
+ end
38
+ end
39
+
40
+ def data_provider=(provider)
41
+ @cache = nil
42
+ @data_provider = provider
43
+ end
34
44
 
35
- private
45
+ private
36
46
 
37
- # hardcode languages that do not have a default type
38
- # e.g. zh does not exist, but zh_CN does
39
- def normal_to_region_code(normal)
40
- {
41
- "ZH" => "zh_CN",
42
- "BN" => "bn_IN",
43
- }[normal] || normal
44
- end
47
+ def fetch(*args)
48
+ @cache ||= {}
49
+ if @cache.key?(args)
50
+ @cache[args]
51
+ else
52
+ @cache[args] = yield
53
+ end
54
+ end
55
+
56
+ # hardcode languages that do not have a default type
57
+ # e.g. zh does not exist, but zh_CN does
58
+ def normal_to_region_code(normal)
59
+ {
60
+ "ZH" => "zh_CN",
61
+ "BN" => "bn_IN",
62
+ }[normal] || normal
63
+ end
64
+
65
+ def recognise_code(type, search)
66
+ search = search.strip
45
67
 
46
- def recognise_code(type, search)
47
- search = search.strip
68
+ # common languages first <-> faster in majority of cases
69
+ common_languages = ['EN','ES','FR','DE','ZH']
70
+ langs = (common_languages + (languages.keys - common_languages))
48
71
 
49
- # common languages first <-> faster in majority of cases
50
- common_languages = ['EN','ES','FR','DE','ZH']
51
- langs = (common_languages + (languages.keys - common_languages))
52
-
53
- langs.each do |code|
54
- begin
55
- send(type, code).each do |code, name|
56
- # supports "Dutch" and "Dutch; Flemish", checks for inclusion first -> faster
57
- match_found = (name.include?(search) and name.split(';').map{|s| s.strip }.include?(search))
58
- return code if match_found
72
+ langs.each do |code|
73
+ begin
74
+ send(type, code).each do |code, name|
75
+ # supports "Dutch" and "Dutch; Flemish", checks for inclusion first -> faster
76
+ match_found = (name.include?(search) and name.split(';').map{|s| s.strip }.include?(search))
77
+ return code if match_found
78
+ end
79
+ rescue NoTranslationAvailable
59
80
  end
60
- rescue NoTranslationAvailable
61
81
  end
62
- end
63
- nil
64
- end
65
-
66
- class NoTranslationAvailable < Exception
67
- def to_s
68
- "NoTranslationAvailable -- #{super}"
82
+ nil
69
83
  end
70
84
  end
71
85
  end
@@ -18,12 +18,18 @@ describe I18nData do
18
18
  I18nData.data_provider = provider
19
19
  end
20
20
 
21
- describe :languages do
21
+ describe ".languages" do
22
22
  it "raises NoTranslationAvailable for unavailable languages" do
23
23
  lambda{I18nData.languages('XX')}.should raise_error(I18nData::NoTranslationAvailable)
24
24
  end
25
25
 
26
- describe :english do
26
+ it "is cached" do
27
+ id = I18nData.languages.object_id
28
+ I18nData.languages.object_id.should == id
29
+ I18nData.languages("DE").object_id.should_not == id
30
+ end
31
+
32
+ describe "english" do
27
33
  it "does not contain blanks" do
28
34
  blank_keys_or_values(I18nData.languages).should == nil
29
35
  end
@@ -37,7 +43,7 @@ describe I18nData do
37
43
  end
38
44
  end
39
45
 
40
- describe :translated do
46
+ describe "translated" do
41
47
  it "is translated" do
42
48
  I18nData.languages('DE')['DE'].should == 'Deutsch'
43
49
  end
@@ -68,8 +74,14 @@ describe I18nData do
68
74
  end
69
75
  end
70
76
 
71
- describe :countries do
72
- describe :english do
77
+ describe ".countries" do
78
+ it "is cached" do
79
+ id = I18nData.countries.object_id
80
+ I18nData.countries.object_id.should == id
81
+ I18nData.countries("DE").object_id.should_not == id
82
+ end
83
+
84
+ describe "english" do
73
85
  it "has english as default" do
74
86
  I18nData.countries['DE'].should == 'Germany'
75
87
  end
@@ -83,7 +95,7 @@ describe I18nData do
83
95
  end
84
96
  end
85
97
 
86
- describe :translated do
98
+ describe "translated" do
87
99
  it "is translated" do
88
100
  I18nData.countries('DE')['DE'].should == 'Deutschland'
89
101
  end
data.tar.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ ��!��;�1������җ�����.�z��FmP�;0[��fIbu��=�]^}Y4�(�T)s���l��6b�{��`!�����nX_n�%ҏd��/�GI�,�%Z��jDH ��:�����4���fwE�u�<a1<�LE���C���\��yޮ(�������ȵ�
2
+ ��!/�H���"y/�ӣ�{ k,���s�w�}}F����EXu,�'��5�tctB������r� M��',����!
metadata CHANGED
@@ -1,15 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Michael Grosser
9
9
  autorequire:
10
10
  bindir: bin
11
- cert_chain: []
12
- date: 2012-09-25 00:00:00.000000000 Z
11
+ cert_chain:
12
+ - !binary |-
13
+ LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0t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FRREFn
30
+ U3dNQTBHQ1NxR1NJYjNEUUVCQlFVQUE0SUJBUUFseU43a0tvL05RQ1EwCkFP
31
+ elpMWjNXQWVQdlN0a0NGSUo1M3RzdjVLeW80cE1BbGx2K0JnUHp6QnQ3cWk2
32
+ MDVtRlNMNnpCZDl1TG91K1cKQ28zczQ4cDFkeTdDampBZlZRZG1WTkhGM013
33
+ WHRmQzJPRXl2U1FQaTR4S1I4aWJhOHdhM3hwOUxWbzFQdUxwdwovNkRzckNo
34
+ V3c3NEhmc0pONnFKT0s2ODRoSmVUOGxCWUFVZmlDM3dEMG93b1BTZytYdHlB
35
+ QWRkaXNSK0tWNVkxCk5tVkh1THRRY05UWnkrZ1JodDNhaEpSTXVDNlF5TG1r
36
+ VHNmKzZNYWVud0FNa0FnSGRzd0dzSnp0T25ObkJhM0YKeTBrQ1NXbUs2RCt4
37
+ L1NiZlM2cjdLZTA3TVJxemlKZEI5R3VFMSswY0lSdUZoOEVRK0xONkhYQ0tN
38
+ NXBvbi9HVQp5Y3dNWGZsMAotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
39
+ date: 2013-02-13 00:00:00.000000000 Z
13
40
  dependencies: []
14
41
  description:
15
42
  email: michael@grosser.it
@@ -200,6 +227,7 @@ files:
200
227
  - example_output/all_names_for_FR.txt
201
228
  - example_output/all_names_for_GB.txt
202
229
  - example_output/all_names_for_US.txt
230
+ - gem-public_cert.pem
203
231
  - i18n_data.gemspec
204
232
  - lib/i18n_data.rb
205
233
  - lib/i18n_data/file_data_provider.rb
@@ -209,7 +237,7 @@ files:
209
237
  - spec/i18n_data/live_data_provider_spec.rb
210
238
  - spec/i18n_data_spec.rb
211
239
  - spec/spec_helper.rb
212
- homepage: http://github.com/grosser/i18n_data
240
+ homepage: https://github.com/grosser/i18n_data
213
241
  licenses:
214
242
  - MIT
215
243
  post_install_message:
@@ -224,7 +252,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
224
252
  version: '0'
225
253
  segments:
226
254
  - 0
227
- hash: 2858300428554998618
255
+ hash: 3936433807610975866
228
256
  required_rubygems_version: !ruby/object:Gem::Requirement
229
257
  none: false
230
258
  requirements:
@@ -233,7 +261,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
261
  version: '0'
234
262
  segments:
235
263
  - 0
236
- hash: 2858300428554998618
264
+ hash: 3936433807610975866
237
265
  requirements: []
238
266
  rubyforge_project:
239
267
  rubygems_version: 1.8.24
metadata.gz.sig ADDED
Binary file