i18n_data 0.4.1 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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 +1 -1
- data/cache/file_data_provider/countries-BG.txt +2 -2
- data/cache/file_data_provider/countries-BN.txt +1 -1
- 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 +1 -1
- data/cache/file_data_provider/countries-CY.txt +1 -1
- data/cache/file_data_provider/countries-DA.txt +1 -1
- data/cache/file_data_provider/countries-DE.txt +3 -3
- data/cache/file_data_provider/countries-DZ.txt +1 -1
- data/cache/file_data_provider/countries-EL.txt +1 -1
- 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 +1 -1
- data/cache/file_data_provider/countries-EU.txt +1 -1
- 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 +1 -1
- 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 +1 -1
- data/cache/file_data_provider/countries-HR.txt +1 -1
- data/cache/file_data_provider/countries-HU.txt +1 -1
- data/cache/file_data_provider/countries-HY.txt +1 -1
- data/cache/file_data_provider/countries-IA.txt +1 -1
- data/cache/file_data_provider/countries-ID.txt +1 -1
- data/cache/file_data_provider/countries-IS.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 +2 -2
- data/cache/file_data_provider/countries-MI.txt +1 -1
- 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 +1 -1
- data/cache/file_data_provider/countries-NE.txt +1 -1
- 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 +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 +29 -29
- data/cache/file_data_provider/countries-SV.txt +1 -1
- 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 +1 -1
- 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_CN.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-DE.txt +74 -74
- data/cache/file_data_provider/languages-SR.txt +105 -105
- data/cache/file_data_provider/languages-TR.txt +46 -46
- data/lib/i18n_data/file_data_provider.rb +0 -18
- data/lib/i18n_data/live_data_provider.rb +27 -30
- data/lib/i18n_data/version.rb +1 -1
- metadata +5 -5
- metadata.gz.sig +0 -0
@@ -12,10 +12,6 @@ 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
|
-
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
15
|
languages.map do |language_code|
|
20
16
|
[:languages, :countries].each do |type|
|
21
17
|
begin
|
@@ -27,25 +23,11 @@ module I18nData
|
|
27
23
|
$stderr.puts "Access denied for #{type} #{language_code}"
|
28
24
|
end
|
29
25
|
end
|
30
|
-
progress_bar.increment if progress_bar
|
31
26
|
end
|
32
27
|
end
|
33
28
|
|
34
29
|
private
|
35
30
|
|
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
|
48
|
-
|
49
31
|
def read_from_file(file)
|
50
32
|
return nil unless File.exist?(file)
|
51
33
|
data = {}
|
@@ -2,22 +2,24 @@ require 'open-uri'
|
|
2
2
|
require 'rexml/document'
|
3
3
|
|
4
4
|
module I18nData
|
5
|
-
# fetches data online from debian
|
5
|
+
# fetches data online from debian git
|
6
6
|
module LiveDataProvider
|
7
7
|
extend self
|
8
8
|
|
9
|
-
ROOT = "http://git.debian.org/?p=iso-codes/iso-codes.git;a=blob_plain;f="
|
10
|
-
|
11
9
|
XML_CODES = {
|
12
|
-
:countries =>
|
13
|
-
:languages =>
|
10
|
+
:countries => 'iso_3166/iso_3166.xml',
|
11
|
+
:languages => 'iso_639/iso_639.xml'
|
14
12
|
}
|
15
13
|
TRANSLATIONS = {
|
16
|
-
:countries =>
|
17
|
-
:languages =>
|
14
|
+
:countries => 'iso_3166/',
|
15
|
+
:languages => 'iso_639/'
|
18
16
|
}
|
17
|
+
REPO = "git://anonscm.debian.org/iso-codes/pkg-iso-codes.git"
|
18
|
+
CLONE_DEST = "/tmp/i18n_data_iso_clone"
|
19
19
|
|
20
20
|
def codes(type, language_code)
|
21
|
+
ensure_checkout
|
22
|
+
|
21
23
|
language_code = language_code.upcase
|
22
24
|
if language_code == 'EN'
|
23
25
|
send("english_#{type}")
|
@@ -26,8 +28,20 @@ module I18nData
|
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
31
|
+
def clear_cache
|
32
|
+
`rm -rf #{CLONE_DEST}`
|
33
|
+
raise unless $?.success?
|
34
|
+
end
|
35
|
+
|
29
36
|
private
|
30
37
|
|
38
|
+
def ensure_checkout
|
39
|
+
unless File.exist?(CLONE_DEST)
|
40
|
+
`git clone #{REPO} #{CLONE_DEST}`
|
41
|
+
raise unless $?.success?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
31
45
|
def translate(type, language, to_language_code)
|
32
46
|
translated = translations(type, to_language_code)[language]
|
33
47
|
translated.to_s.empty? ? nil : translated
|
@@ -49,18 +63,11 @@ module I18nData
|
|
49
63
|
code[0].downcase!
|
50
64
|
code = code.join("_")
|
51
65
|
|
66
|
+
url = TRANSLATIONS[type]+"#{code}.po"
|
52
67
|
begin
|
53
|
-
url = TRANSLATIONS[type]+"#{code}.po"
|
54
68
|
data = get(url)
|
55
|
-
rescue
|
56
|
-
|
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
|
69
|
+
rescue Errno::ENOENT
|
70
|
+
raise NoTranslationAvailable, "for #{type} and language code = #{code} (#{$!})"
|
64
71
|
end
|
65
72
|
|
66
73
|
data = data.force_encoding('utf-8') if data.respond_to?(:force_encoding) # 1.9
|
@@ -87,6 +94,7 @@ module I18nData
|
|
87
94
|
codes = {}
|
88
95
|
xml(:countries).elements.each('*/iso_3166_entry') do |entry|
|
89
96
|
name = entry.attributes['name'].to_s.gsub("'", "\\'")
|
97
|
+
name = "Taiwan" if name == "Taiwan, Province of China"
|
90
98
|
code = entry.attributes['alpha_2_code'].to_s.upcase
|
91
99
|
codes[code] = name
|
92
100
|
end
|
@@ -104,22 +112,11 @@ module I18nData
|
|
104
112
|
end
|
105
113
|
|
106
114
|
def get(url)
|
107
|
-
|
108
|
-
@@cache ||= {}
|
109
|
-
return @@cache[url] if @@cache.include? url
|
110
|
-
@@cache[url] = open(url).read
|
115
|
+
File.read("#{CLONE_DEST}/#{url}")
|
111
116
|
end
|
112
117
|
|
113
118
|
def xml(type)
|
114
|
-
|
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
|
119
|
+
REXML::Document.new(get(XML_CODES[type]))
|
123
120
|
end
|
124
121
|
end
|
125
122
|
end
|
data/lib/i18n_data/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
F5etKHZg0j3eHO31/i2HnswY04lqGImUu6aM5EnijFTB7PPW2KwKKM4+kKDYFdlw
|
31
31
|
/0WV1Ng2/Y6qsHwmqGg2VlYj2h4=
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2014-
|
33
|
+
date: 2014-06-16 00:00:00.000000000 Z
|
34
34
|
dependencies: []
|
35
35
|
description:
|
36
36
|
email: michael@grosser.it
|
@@ -226,17 +226,17 @@ require_paths:
|
|
226
226
|
- lib
|
227
227
|
required_ruby_version: !ruby/object:Gem::Requirement
|
228
228
|
requirements:
|
229
|
-
- -
|
229
|
+
- - ">="
|
230
230
|
- !ruby/object:Gem::Version
|
231
231
|
version: '0'
|
232
232
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
233
233
|
requirements:
|
234
|
-
- -
|
234
|
+
- - ">="
|
235
235
|
- !ruby/object:Gem::Version
|
236
236
|
version: '0'
|
237
237
|
requirements: []
|
238
238
|
rubyforge_project:
|
239
|
-
rubygems_version: 2.
|
239
|
+
rubygems_version: 2.2.2
|
240
240
|
signing_key:
|
241
241
|
specification_version: 4
|
242
242
|
summary: country/language names and 2-letter-code pairs, in 85 languages
|
metadata.gz.sig
CHANGED
Binary file
|