i18n_data 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/cache/file_data_provider/countries-AF.txt +1 -1
- data/cache/file_data_provider/countries-AM.txt +1 -1
- data/cache/file_data_provider/countries-AR.txt +1 -1
- data/cache/file_data_provider/countries-AS.txt +1 -1
- data/cache/file_data_provider/countries-AZ.txt +1 -1
- data/cache/file_data_provider/countries-BE.txt +62 -62
- data/cache/file_data_provider/countries-BG.txt +1 -1
- data/cache/file_data_provider/countries-BN.txt +123 -123
- data/cache/file_data_provider/countries-BN_IN.txt +1 -1
- data/cache/file_data_provider/countries-BR.txt +1 -1
- data/cache/file_data_provider/countries-BS.txt +1 -1
- data/cache/file_data_provider/countries-CA.txt +1 -1
- data/cache/file_data_provider/countries-CS.txt +5 -5
- data/cache/file_data_provider/countries-CY.txt +1 -1
- data/cache/file_data_provider/countries-DA.txt +2 -2
- data/cache/file_data_provider/countries-DE.txt +1 -1
- data/cache/file_data_provider/countries-DZ.txt +1 -1
- data/cache/file_data_provider/countries-EL.txt +2 -2
- data/cache/file_data_provider/countries-EN.txt +1 -1
- data/cache/file_data_provider/countries-EO.txt +1 -1
- data/cache/file_data_provider/countries-ES.txt +4 -4
- data/cache/file_data_provider/countries-ET.txt +2 -2
- data/cache/file_data_provider/countries-EU.txt +2 -2
- data/cache/file_data_provider/countries-FA.txt +1 -1
- data/cache/file_data_provider/countries-FI.txt +1 -1
- data/cache/file_data_provider/countries-FO.txt +1 -1
- data/cache/file_data_provider/countries-FR.txt +1 -1
- data/cache/file_data_provider/countries-GA.txt +3 -3
- data/cache/file_data_provider/countries-GL.txt +1 -1
- data/cache/file_data_provider/countries-GU.txt +1 -1
- data/cache/file_data_provider/countries-HE.txt +1 -1
- data/cache/file_data_provider/countries-HI.txt +10 -10
- data/cache/file_data_provider/countries-HU.txt +1 -1
- data/cache/file_data_provider/countries-HY.txt +75 -75
- data/cache/file_data_provider/countries-IA.txt +249 -0
- data/cache/file_data_provider/countries-ID.txt +1 -1
- data/cache/file_data_provider/countries-IS.txt +6 -6
- data/cache/file_data_provider/countries-IT.txt +1 -1
- data/cache/file_data_provider/countries-JA.txt +1 -1
- data/cache/file_data_provider/countries-KA.txt +1 -1
- data/cache/file_data_provider/countries-KK.txt +1 -1
- data/cache/file_data_provider/countries-KM.txt +1 -1
- data/cache/file_data_provider/countries-KN.txt +1 -1
- data/cache/file_data_provider/countries-KO.txt +1 -1
- data/cache/file_data_provider/countries-KU.txt +1 -1
- data/cache/file_data_provider/countries-LT.txt +1 -1
- data/cache/file_data_provider/countries-LV.txt +1 -1
- data/cache/file_data_provider/countries-MI.txt +169 -169
- data/cache/file_data_provider/countries-MK.txt +1 -1
- data/cache/file_data_provider/countries-ML.txt +1 -1
- data/cache/file_data_provider/countries-MN.txt +1 -1
- data/cache/file_data_provider/countries-MR.txt +1 -1
- data/cache/file_data_provider/countries-MS.txt +1 -1
- data/cache/file_data_provider/countries-MT.txt +1 -1
- data/cache/file_data_provider/countries-NB.txt +2 -2
- data/cache/file_data_provider/countries-NE.txt +1 -1
- data/cache/file_data_provider/countries-NN.txt +7 -7
- data/cache/file_data_provider/countries-OC.txt +1 -1
- data/cache/file_data_provider/countries-OR.txt +1 -1
- data/cache/file_data_provider/countries-PA.txt +1 -1
- data/cache/file_data_provider/countries-PL.txt +1 -1
- data/cache/file_data_provider/countries-PS.txt +1 -1
- data/cache/file_data_provider/countries-PT.txt +1 -1
- data/cache/file_data_provider/countries-PT_BR.txt +8 -8
- data/cache/file_data_provider/countries-RO.txt +1 -1
- data/cache/file_data_provider/countries-RU.txt +1 -1
- data/cache/file_data_provider/countries-RW.txt +1 -1
- data/cache/file_data_provider/countries-SI.txt +1 -1
- data/cache/file_data_provider/countries-SK.txt +1 -1
- data/cache/file_data_provider/countries-SL.txt +1 -1
- data/cache/file_data_provider/countries-SO.txt +1 -1
- data/cache/file_data_provider/countries-SQ.txt +1 -1
- data/cache/file_data_provider/countries-SR.txt +1 -1
- data/cache/file_data_provider/countries-SV.txt +2 -2
- data/cache/file_data_provider/countries-SW.txt +1 -1
- data/cache/file_data_provider/countries-TA.txt +1 -1
- data/cache/file_data_provider/countries-TE.txt +1 -1
- data/cache/file_data_provider/countries-TH.txt +1 -1
- data/cache/file_data_provider/countries-TI.txt +1 -1
- data/cache/file_data_provider/countries-TK.txt +1 -1
- data/cache/file_data_provider/countries-TL.txt +1 -1
- data/cache/file_data_provider/countries-TR.txt +1 -1
- data/cache/file_data_provider/countries-TT.txt +228 -228
- data/cache/file_data_provider/countries-UG.txt +2 -2
- data/cache/file_data_provider/countries-UK.txt +1 -1
- data/cache/file_data_provider/countries-VE.txt +1 -1
- data/cache/file_data_provider/countries-VI.txt +1 -1
- data/cache/file_data_provider/countries-WA.txt +1 -1
- data/cache/file_data_provider/countries-WO.txt +1 -1
- data/cache/file_data_provider/countries-XH.txt +1 -1
- data/cache/file_data_provider/countries-ZH_HK.txt +1 -1
- data/cache/file_data_provider/countries-ZH_TW.txt +1 -1
- data/cache/file_data_provider/countries-ZU.txt +1 -1
- data/cache/file_data_provider/languages-BG.txt +7 -7
- data/cache/file_data_provider/{languages-BN_IN.txt → languages-BN.txt} +0 -0
- data/cache/file_data_provider/languages-DA.txt +184 -184
- data/cache/file_data_provider/languages-DE.txt +1 -1
- data/cache/file_data_provider/languages-HR.txt +4 -4
- data/cache/file_data_provider/languages-PT.txt +20 -20
- data/cache/file_data_provider/languages-TH.txt +12 -12
- data/cache/file_data_provider/languages-TR.txt +10 -10
- data/cache/file_data_provider/languages-TT.txt +150 -150
- data/cache/file_data_provider/languages-VI.txt +1 -1
- data/cache/file_data_provider/languages-ZH_TW.txt +1 -1
- data/lib/i18n_data.rb +7 -2
- data/lib/i18n_data/file_data_provider.rb +23 -2
- data/lib/i18n_data/live_data_provider.rb +25 -4
- data/lib/i18n_data/version.rb +1 -1
- metadata +31 -59
- metadata.gz.sig +0 -0
- data/.gitignore +0 -3
- data/.travis.yml +0 -4
- data/Gemfile +0 -6
- data/Gemfile.lock +0 -28
- data/Rakefile +0 -77
- data/Readme.md +0 -61
- data/example_output/all_names_for_DE.txt +0 -85
- data/example_output/all_names_for_FR.txt +0 -85
- data/example_output/all_names_for_GB.txt +0 -85
- data/example_output/all_names_for_US.txt +0 -85
- data/gem-public_cert.pem +0 -20
- data/i18n_data.gemspec +0 -14
- data/spec/i18n_data/file_data_provider_spec.rb +0 -29
- data/spec/i18n_data/live_data_provider_spec.rb +0 -45
- data/spec/i18n_data_spec.rb +0 -176
- data/spec/spec_helper.rb +0 -2
data/lib/i18n_data.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
require 'i18n_data/version'
|
2
2
|
|
3
3
|
module I18nData
|
4
|
-
|
4
|
+
|
5
|
+
class BaseException < Exception
|
5
6
|
def to_s
|
6
|
-
"
|
7
|
+
"#{self.class} -- #{super}"
|
7
8
|
end
|
8
9
|
end
|
9
10
|
|
11
|
+
class NoTranslationAvailable < BaseException; end
|
12
|
+
class AccessDenied < BaseException; end
|
13
|
+
class Unknown < BaseException; end
|
14
|
+
|
10
15
|
class << self
|
11
16
|
def languages(language_code='EN')
|
12
17
|
fetch :languages, language_code do
|
@@ -12,18 +12,39 @@ module I18nData
|
|
12
12
|
|
13
13
|
def write_cache(provider)
|
14
14
|
languages = provider.codes(:languages, 'EN').keys + ['zh_CN', 'zh_TW', 'zh_HK','bn_IN','pt_BR']
|
15
|
-
languages.
|
15
|
+
unless progress_bar = build_progress_bar(languages.count)
|
16
|
+
$stderr.puts 'i18n_data: Updating file cache, will take about 8 minutes...'
|
17
|
+
end
|
18
|
+
|
19
|
+
languages.map do |language_code|
|
16
20
|
[:languages, :countries].each do |type|
|
17
21
|
begin
|
18
22
|
data = provider.send(:codes, type, language_code)
|
19
23
|
write_to_file(data, cache_file_for(type, language_code))
|
20
24
|
rescue NoTranslationAvailable
|
25
|
+
$stderr.puts "No translation available for #{type} #{language_code}" if $DEBUG
|
26
|
+
rescue AccessDenied
|
27
|
+
$stderr.puts "Access denied for #{type} #{language_code}"
|
21
28
|
end
|
22
29
|
end
|
30
|
+
progress_bar.increment if progress_bar
|
23
31
|
end
|
24
32
|
end
|
25
33
|
|
26
|
-
|
34
|
+
private
|
35
|
+
|
36
|
+
def build_progress_bar(max_count)
|
37
|
+
return unless $stderr.tty?
|
38
|
+
require 'ruby-progressbar'
|
39
|
+
ProgressBar.create(
|
40
|
+
:format => '%t %E: |%w|',
|
41
|
+
:title => 'writing translation cache data',
|
42
|
+
:total => max_count
|
43
|
+
)
|
44
|
+
rescue LoadError
|
45
|
+
$stderr.puts ':: i18n_data file write cache update ::'
|
46
|
+
$stderr.puts 'for progress install "ruby-progressbar" gem'
|
47
|
+
end
|
27
48
|
|
28
49
|
def read_from_file(file)
|
29
50
|
return nil unless File.exist?(file)
|
@@ -51,9 +51,16 @@ module I18nData
|
|
51
51
|
|
52
52
|
begin
|
53
53
|
url = TRANSLATIONS[type]+"#{code}.po"
|
54
|
-
data =
|
55
|
-
rescue
|
56
|
-
|
54
|
+
data = get(url)
|
55
|
+
rescue => e
|
56
|
+
case e.to_s
|
57
|
+
when /\A404 /
|
58
|
+
raise NoTranslationAvailable, "for #{type} and language code = #{code} (#{$!})"
|
59
|
+
when /\A502 /
|
60
|
+
raise AccessDenied, "for #{type} and language code = #{code} (#{$!})"
|
61
|
+
else
|
62
|
+
raise Unknown, "#{e.to_s} for #{type} and language code = #{code} (#{$!})"
|
63
|
+
end
|
57
64
|
end
|
58
65
|
|
59
66
|
data = data.force_encoding('utf-8') if data.respond_to?(:force_encoding) # 1.9
|
@@ -96,9 +103,23 @@ module I18nData
|
|
96
103
|
end]
|
97
104
|
end
|
98
105
|
|
106
|
+
def get(url)
|
107
|
+
$stderr.puts "GET #{url}" if $DEBUG
|
108
|
+
@@cache ||= {}
|
109
|
+
return @@cache[url] if @@cache.include? url
|
110
|
+
@@cache[url] = open(url).read
|
111
|
+
end
|
112
|
+
|
99
113
|
def xml(type)
|
100
|
-
xml =
|
114
|
+
xml = get(XML_CODES[type])
|
101
115
|
REXML::Document.new(xml)
|
116
|
+
rescue => e
|
117
|
+
case e.to_s
|
118
|
+
when /\A502 /
|
119
|
+
raise AccessDenied, "for index of #{type} (#{$!})"
|
120
|
+
else
|
121
|
+
raise Unknown, "#{e.to_s} for index of #{type} (#{$!})"
|
122
|
+
end
|
102
123
|
end
|
103
124
|
end
|
104
125
|
end
|
data/lib/i18n_data/version.rb
CHANGED
metadata
CHANGED
@@ -1,42 +1,36 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Michael Grosser
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain:
|
12
|
-
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
QWRkaXNSK0tWNVkxCk5tVkh1THRRY05UWnkrZ1JodDNhaEpSTXVDNlF5TG1r
|
36
|
-
VHNmKzZNYWVud0FNa0FnSGRzd0dzSnp0T25ObkJhM0YKeTBrQ1NXbUs2RCt4
|
37
|
-
L1NiZlM2cjdLZTA3TVJxemlKZEI5R3VFMSswY0lSdUZoOEVRK0xONkhYQ0tN
|
38
|
-
NXBvbi9HVQp5Y3dNWGZsMAotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
|
39
|
-
date: 2013-02-13 00:00:00.000000000 Z
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MRAwDgYDVQQDDAdtaWNo
|
14
|
+
YWVsMRcwFQYKCZImiZPyLGQBGRYHZ3Jvc3NlcjESMBAGCgmSJomT8ixkARkWAml0
|
15
|
+
MB4XDTE0MDIwNDIwMjk0MVoXDTE1MDIwNDIwMjk0MVowPzEQMA4GA1UEAwwHbWlj
|
16
|
+
aGFlbDEXMBUGCgmSJomT8ixkARkWB2dyb3NzZXIxEjAQBgoJkiaJk/IsZAEZFgJp
|
17
|
+
dDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMorXo/hgbUq97+kII9H
|
18
|
+
MsQcLdC/7wQ1ZP2OshVHPkeP0qH8MBHGg6eYisOX2ubNagF9YTCZWnhrdKrwpLOO
|
19
|
+
cPLaZbjUjljJ3cQR3B8Yn1veV5IhG86QseTBjymzJWsLpqJ1UZGpfB9tXcsFtuxO
|
20
|
+
6vHvcIHdzvc/OUkICttLbH+1qb6rsHUceqh+JrH4GrsJ5H4hAfIdyS2XMK7YRKbh
|
21
|
+
h+IBu6dFWJJByzFsYmV1PDXln3UBmgAt65cmCu4qPfThioCGDzbSJrGDGLmw/pFX
|
22
|
+
FPpVCm1zgYSb1v6Qnf3cgXa2f2wYGm17+zAVyIDpwryFru9yF/jJxE38z/DRsd9R
|
23
|
+
/88CAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFLIj
|
24
|
+
Z1x7SnjGGHK+MiVZkFjjS/iMMB0GA1UdEQQWMBSBEm1pY2hhZWxAZ3Jvc3Nlci5p
|
25
|
+
dDAdBgNVHRIEFjAUgRJtaWNoYWVsQGdyb3NzZXIuaXQwDQYJKoZIhvcNAQEFBQAD
|
26
|
+
ggEBAExBcUWfGuamYn+IddOA0Ws8jUKwB14RXoZRDrTiTAlMm3Bkg2OKyxS3uJXa
|
27
|
+
6Z+LwFiZwVYk62yHXqNzEJycQk4SEmY+xDWLj0p7X6qEeU4QZKwR1TwJ5z3PTrZ6
|
28
|
+
irJgM3q7NIBRvmTzRaAghWcQn+Eyr5YLOfMksjVBMUMnzh5/ZDgq53LphgJbGwvz
|
29
|
+
ScJAgfNclLHnjk9q1mT1s0e1FPWbiAL3siBIR5HpH8qtSEiivTf2ntciebOqS93f
|
30
|
+
F5etKHZg0j3eHO31/i2HnswY04lqGImUu6aM5EnijFTB7PPW2KwKKM4+kKDYFdlw
|
31
|
+
/0WV1Ng2/Y6qsHwmqGg2VlYj2h4=
|
32
|
+
-----END CERTIFICATE-----
|
33
|
+
date: 2014-03-15 00:00:00.000000000 Z
|
40
34
|
dependencies: []
|
41
35
|
description:
|
42
36
|
email: michael@grosser.it
|
@@ -44,12 +38,6 @@ executables: []
|
|
44
38
|
extensions: []
|
45
39
|
extra_rdoc_files: []
|
46
40
|
files:
|
47
|
-
- .gitignore
|
48
|
-
- .travis.yml
|
49
|
-
- Gemfile
|
50
|
-
- Gemfile.lock
|
51
|
-
- Rakefile
|
52
|
-
- Readme.md
|
53
41
|
- cache/file_data_provider/countries-AF.txt
|
54
42
|
- cache/file_data_provider/countries-AM.txt
|
55
43
|
- cache/file_data_provider/countries-AR.txt
|
@@ -85,6 +73,7 @@ files:
|
|
85
73
|
- cache/file_data_provider/countries-HR.txt
|
86
74
|
- cache/file_data_provider/countries-HU.txt
|
87
75
|
- cache/file_data_provider/countries-HY.txt
|
76
|
+
- cache/file_data_provider/countries-IA.txt
|
88
77
|
- cache/file_data_provider/countries-ID.txt
|
89
78
|
- cache/file_data_provider/countries-IS.txt
|
90
79
|
- cache/file_data_provider/countries-IT.txt
|
@@ -152,7 +141,7 @@ files:
|
|
152
141
|
- cache/file_data_provider/languages-AZ.txt
|
153
142
|
- cache/file_data_provider/languages-BE.txt
|
154
143
|
- cache/file_data_provider/languages-BG.txt
|
155
|
-
- cache/file_data_provider/languages-
|
144
|
+
- cache/file_data_provider/languages-BN.txt
|
156
145
|
- cache/file_data_provider/languages-BR.txt
|
157
146
|
- cache/file_data_provider/languages-BS.txt
|
158
147
|
- cache/file_data_provider/languages-CA.txt
|
@@ -223,49 +212,32 @@ files:
|
|
223
212
|
- cache/file_data_provider/languages-ZH_HK.txt
|
224
213
|
- cache/file_data_provider/languages-ZH_TW.txt
|
225
214
|
- cache/file_data_provider/languages-ZU.txt
|
226
|
-
- example_output/all_names_for_DE.txt
|
227
|
-
- example_output/all_names_for_FR.txt
|
228
|
-
- example_output/all_names_for_GB.txt
|
229
|
-
- example_output/all_names_for_US.txt
|
230
|
-
- gem-public_cert.pem
|
231
|
-
- i18n_data.gemspec
|
232
215
|
- lib/i18n_data.rb
|
233
216
|
- lib/i18n_data/file_data_provider.rb
|
234
217
|
- lib/i18n_data/live_data_provider.rb
|
235
218
|
- lib/i18n_data/version.rb
|
236
|
-
- spec/i18n_data/file_data_provider_spec.rb
|
237
|
-
- spec/i18n_data/live_data_provider_spec.rb
|
238
|
-
- spec/i18n_data_spec.rb
|
239
|
-
- spec/spec_helper.rb
|
240
219
|
homepage: https://github.com/grosser/i18n_data
|
241
220
|
licenses:
|
242
221
|
- MIT
|
222
|
+
metadata: {}
|
243
223
|
post_install_message:
|
244
224
|
rdoc_options: []
|
245
225
|
require_paths:
|
246
226
|
- lib
|
247
227
|
required_ruby_version: !ruby/object:Gem::Requirement
|
248
|
-
none: false
|
249
228
|
requirements:
|
250
|
-
- -
|
229
|
+
- - '>='
|
251
230
|
- !ruby/object:Gem::Version
|
252
231
|
version: '0'
|
253
|
-
segments:
|
254
|
-
- 0
|
255
|
-
hash: 3936433807610975866
|
256
232
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
257
|
-
none: false
|
258
233
|
requirements:
|
259
|
-
- -
|
234
|
+
- - '>='
|
260
235
|
- !ruby/object:Gem::Version
|
261
236
|
version: '0'
|
262
|
-
segments:
|
263
|
-
- 0
|
264
|
-
hash: 3936433807610975866
|
265
237
|
requirements: []
|
266
238
|
rubyforge_project:
|
267
|
-
rubygems_version:
|
239
|
+
rubygems_version: 2.0.14
|
268
240
|
signing_key:
|
269
|
-
specification_version:
|
241
|
+
specification_version: 4
|
270
242
|
summary: country/language names and 2-letter-code pairs, in 85 languages
|
271
243
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
i18n_data (0.4.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: http://rubygems.org/
|
8
|
-
specs:
|
9
|
-
bump (0.3.9)
|
10
|
-
diff-lcs (1.1.3)
|
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)
|
20
|
-
|
21
|
-
PLATFORMS
|
22
|
-
ruby
|
23
|
-
|
24
|
-
DEPENDENCIES
|
25
|
-
bump
|
26
|
-
i18n_data!
|
27
|
-
rake
|
28
|
-
rspec (~> 2)
|
data/Rakefile
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'bundler/gem_tasks'
|
2
|
-
require 'bump/tasks'
|
3
|
-
$LOAD_PATH << "lib"
|
4
|
-
require 'i18n_data'
|
5
|
-
|
6
|
-
task :default do
|
7
|
-
sh "rspec spec/"
|
8
|
-
end
|
9
|
-
|
10
|
-
desc "write all languages to output"
|
11
|
-
task :all_languages do
|
12
|
-
I18nData.languages.keys.each do |lc|
|
13
|
-
`rake languages LANGUAGE=#{lc}`
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
desc "write languages to output/languages_{language}"
|
18
|
-
task :languages do
|
19
|
-
raise unless language = ENV['LANGUAGE']
|
20
|
-
`mkdir output -p`
|
21
|
-
data = I18nData.languages(language.upcase)
|
22
|
-
File.open("output/languages_#{language.downcase}.yml",'w') {|f|f.puts data.to_yaml}
|
23
|
-
end
|
24
|
-
|
25
|
-
desc "write all countries to output"
|
26
|
-
task :all_countries do
|
27
|
-
I18nData.languages.keys.each do |lc|
|
28
|
-
`rake countries LANGUAGE=#{lc}`
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
desc "write countries to output/countries_{language}"
|
33
|
-
task :countries do
|
34
|
-
raise unless language = ENV['LANGUAGE']
|
35
|
-
`mkdir output -p`
|
36
|
-
data = I18nData.countries(language.upcase)
|
37
|
-
File.open("output/countries_#{language.downcase}.yml",'w') {|f|f.puts data.to_yaml}
|
38
|
-
end
|
39
|
-
|
40
|
-
desc "write example output, just to show off :D"
|
41
|
-
task :example_output do
|
42
|
-
`mkdir example_output -p`
|
43
|
-
|
44
|
-
#all names for germany, france, united kingdom and unites states
|
45
|
-
['DE','FR','GB','US'].each do |cc|
|
46
|
-
names = I18nData.languages.keys.map do |lc|
|
47
|
-
begin
|
48
|
-
[I18nData.countries(lc)[cc], I18nData.languages[lc]]
|
49
|
-
rescue I18nData::NoTranslationAvailable
|
50
|
-
nil
|
51
|
-
end
|
52
|
-
end
|
53
|
-
File.open("example_output/all_names_for_#{cc}.txt",'w') do |f|
|
54
|
-
f.puts names.reject(&:nil?).map{|x|x*" ---- "} * "\n"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
desc "show stats"
|
60
|
-
task :stats do
|
61
|
-
dir = "cache/file_data_provider"
|
62
|
-
[:languages, :countries].each do |type|
|
63
|
-
files = FileList["#{dir}/#{type}*"]
|
64
|
-
lines = File.readlines(files.first).reject{|l|l.empty?}
|
65
|
-
puts "#{lines.size} #{type} in #{files.size} languages"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
desc "write cache for I18nData::FileDataProvider"
|
70
|
-
task :write_cache_for_file_data_provider do
|
71
|
-
raise "use 1.9+, we need sorted hashes or diff is giant" if RUBY_VERSION < "1.9"
|
72
|
-
require 'i18n_data/file_data_provider'
|
73
|
-
require 'i18n_data/live_data_provider'
|
74
|
-
sh "rm -rf cache/file_data_provider" # clean everything so old stuff goes away
|
75
|
-
puts "writing new caches, this can take a few minutes..."
|
76
|
-
I18nData::FileDataProvider.write_cache(I18nData::LiveDataProvider)
|
77
|
-
end
|
data/Readme.md
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
- Present users coutries/languages in their language
|
2
|
-
- Convert a country/language-name to its 2-letter-code
|
3
|
-
- List of 2-letter-code/name pairs for all countries/languages in all languages
|
4
|
-
|
5
|
-
###Translations
|
6
|
-
Through [pkg-isocodes](http://git.debian.org/?p=iso-codes/iso-codes.git):
|
7
|
-
|
8
|
-
- 185 Language codes (iso 639 - 2 letter) in 68 Languages
|
9
|
-
- 246 Country codes (iso 3166 - 2 letter) in 86 Languages
|
10
|
-
- contry specific codes e.g. zh_TW are also available, have a look at the isocodes website for all options
|
11
|
-
|
12
|
-
Install
|
13
|
-
=======
|
14
|
-
|
15
|
-
gem install i18n_data
|
16
|
-
|
17
|
-
Usage
|
18
|
-
=====
|
19
|
-
|
20
|
-
require 'i18n_data'
|
21
|
-
...
|
22
|
-
I18nData.languages # {"DE"=>"German",...}
|
23
|
-
I18nData.languages('DE') # {"DE"=>"Deutsch",...}
|
24
|
-
I18nData.languages('FR') # {"DE"=>"Allemand",...}
|
25
|
-
...
|
26
|
-
|
27
|
-
I18nData.countries # {"DE"=>"Germany",...}
|
28
|
-
I18nData.countries('DE') # {"DE"=>"Deutschland",...}
|
29
|
-
...
|
30
|
-
|
31
|
-
I18nData.language_code('German') # DE
|
32
|
-
I18nData.language_code('Deutsch') # DE
|
33
|
-
I18nData.language_code('Allemand') # DE
|
34
|
-
..
|
35
|
-
|
36
|
-
I18nData.country_code('Germany') # DE
|
37
|
-
I18nData.country_code('Deutschland') # DE
|
38
|
-
..
|
39
|
-
|
40
|
-
Data Providers
|
41
|
-
==============
|
42
|
-
- FileDataProvider: _FAST_ (default) (loading data from cache-files)
|
43
|
-
- LiveDataProvider: _SLOW_ (fetching up-to-date data from svn repos)
|
44
|
-
|
45
|
-
Development
|
46
|
-
=======
|
47
|
-
- update FileDataProvider caches after each code-change to make changes available to users `rake write_cache_for_file_data_provider`
|
48
|
-
- FileDataProvider tests might fail if caches are not updates
|
49
|
-
|
50
|
-
TODO
|
51
|
-
====
|
52
|
-
- include other language/country code formats (3-letter codes...) ?
|
53
|
-
- parse list of files on isocodes for write_cache instead of hardcoding country-specific ones
|
54
|
-
|
55
|
-
Author
|
56
|
-
======
|
57
|
-
[Michael Grosser](http://grosser.it)<br/>
|
58
|
-
michael@grosser.it<br/>
|
59
|
-
License: MIT<br/>
|
60
|
-
[![Build Status](https://travis-ci.org/grosser/i18n_data.png)](https://travis-ci.org/grosser/i18n_data)
|
61
|
-
|