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.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/cache/file_data_provider/countries-AF.txt +1 -1
  5. data/cache/file_data_provider/countries-AM.txt +1 -1
  6. data/cache/file_data_provider/countries-AR.txt +1 -1
  7. data/cache/file_data_provider/countries-AS.txt +1 -1
  8. data/cache/file_data_provider/countries-AZ.txt +1 -1
  9. data/cache/file_data_provider/countries-BE.txt +1 -1
  10. data/cache/file_data_provider/countries-BG.txt +2 -2
  11. data/cache/file_data_provider/countries-BN.txt +1 -1
  12. data/cache/file_data_provider/countries-BN_IN.txt +1 -1
  13. data/cache/file_data_provider/countries-BR.txt +1 -1
  14. data/cache/file_data_provider/countries-BS.txt +1 -1
  15. data/cache/file_data_provider/countries-CA.txt +1 -1
  16. data/cache/file_data_provider/countries-CS.txt +1 -1
  17. data/cache/file_data_provider/countries-CY.txt +1 -1
  18. data/cache/file_data_provider/countries-DA.txt +1 -1
  19. data/cache/file_data_provider/countries-DE.txt +3 -3
  20. data/cache/file_data_provider/countries-DZ.txt +1 -1
  21. data/cache/file_data_provider/countries-EL.txt +1 -1
  22. data/cache/file_data_provider/countries-EN.txt +1 -1
  23. data/cache/file_data_provider/countries-EO.txt +1 -1
  24. data/cache/file_data_provider/countries-ES.txt +1 -1
  25. data/cache/file_data_provider/countries-EU.txt +1 -1
  26. data/cache/file_data_provider/countries-FA.txt +1 -1
  27. data/cache/file_data_provider/countries-FI.txt +1 -1
  28. data/cache/file_data_provider/countries-FO.txt +1 -1
  29. data/cache/file_data_provider/countries-FR.txt +1 -1
  30. data/cache/file_data_provider/countries-GA.txt +1 -1
  31. data/cache/file_data_provider/countries-GL.txt +1 -1
  32. data/cache/file_data_provider/countries-GU.txt +1 -1
  33. data/cache/file_data_provider/countries-HE.txt +1 -1
  34. data/cache/file_data_provider/countries-HI.txt +1 -1
  35. data/cache/file_data_provider/countries-HR.txt +1 -1
  36. data/cache/file_data_provider/countries-HU.txt +1 -1
  37. data/cache/file_data_provider/countries-HY.txt +1 -1
  38. data/cache/file_data_provider/countries-IA.txt +1 -1
  39. data/cache/file_data_provider/countries-ID.txt +1 -1
  40. data/cache/file_data_provider/countries-IS.txt +1 -1
  41. data/cache/file_data_provider/countries-JA.txt +1 -1
  42. data/cache/file_data_provider/countries-KA.txt +1 -1
  43. data/cache/file_data_provider/countries-KK.txt +1 -1
  44. data/cache/file_data_provider/countries-KM.txt +1 -1
  45. data/cache/file_data_provider/countries-KN.txt +1 -1
  46. data/cache/file_data_provider/countries-KO.txt +1 -1
  47. data/cache/file_data_provider/countries-KU.txt +1 -1
  48. data/cache/file_data_provider/countries-LT.txt +1 -1
  49. data/cache/file_data_provider/countries-LV.txt +2 -2
  50. data/cache/file_data_provider/countries-MI.txt +1 -1
  51. data/cache/file_data_provider/countries-MK.txt +1 -1
  52. data/cache/file_data_provider/countries-ML.txt +1 -1
  53. data/cache/file_data_provider/countries-MN.txt +1 -1
  54. data/cache/file_data_provider/countries-MR.txt +1 -1
  55. data/cache/file_data_provider/countries-MS.txt +1 -1
  56. data/cache/file_data_provider/countries-MT.txt +1 -1
  57. data/cache/file_data_provider/countries-NB.txt +1 -1
  58. data/cache/file_data_provider/countries-NE.txt +1 -1
  59. data/cache/file_data_provider/countries-OC.txt +1 -1
  60. data/cache/file_data_provider/countries-OR.txt +1 -1
  61. data/cache/file_data_provider/countries-PA.txt +1 -1
  62. data/cache/file_data_provider/countries-PL.txt +1 -1
  63. data/cache/file_data_provider/countries-PS.txt +1 -1
  64. data/cache/file_data_provider/countries-PT.txt +1 -1
  65. data/cache/file_data_provider/countries-PT_BR.txt +1 -1
  66. data/cache/file_data_provider/countries-RU.txt +1 -1
  67. data/cache/file_data_provider/countries-RW.txt +1 -1
  68. data/cache/file_data_provider/countries-SI.txt +1 -1
  69. data/cache/file_data_provider/countries-SK.txt +1 -1
  70. data/cache/file_data_provider/countries-SL.txt +1 -1
  71. data/cache/file_data_provider/countries-SO.txt +1 -1
  72. data/cache/file_data_provider/countries-SQ.txt +1 -1
  73. data/cache/file_data_provider/countries-SR.txt +29 -29
  74. data/cache/file_data_provider/countries-SV.txt +1 -1
  75. data/cache/file_data_provider/countries-SW.txt +1 -1
  76. data/cache/file_data_provider/countries-TA.txt +1 -1
  77. data/cache/file_data_provider/countries-TE.txt +1 -1
  78. data/cache/file_data_provider/countries-TH.txt +1 -1
  79. data/cache/file_data_provider/countries-TI.txt +1 -1
  80. data/cache/file_data_provider/countries-TK.txt +1 -1
  81. data/cache/file_data_provider/countries-TL.txt +1 -1
  82. data/cache/file_data_provider/countries-TR.txt +1 -1
  83. data/cache/file_data_provider/countries-TT.txt +1 -1
  84. data/cache/file_data_provider/countries-UK.txt +1 -1
  85. data/cache/file_data_provider/countries-VE.txt +1 -1
  86. data/cache/file_data_provider/countries-VI.txt +1 -1
  87. data/cache/file_data_provider/countries-WA.txt +1 -1
  88. data/cache/file_data_provider/countries-WO.txt +1 -1
  89. data/cache/file_data_provider/countries-XH.txt +1 -1
  90. data/cache/file_data_provider/countries-ZH_CN.txt +1 -1
  91. data/cache/file_data_provider/countries-ZH_HK.txt +1 -1
  92. data/cache/file_data_provider/countries-ZH_TW.txt +1 -1
  93. data/cache/file_data_provider/countries-ZU.txt +1 -1
  94. data/cache/file_data_provider/languages-DE.txt +74 -74
  95. data/cache/file_data_provider/languages-SR.txt +105 -105
  96. data/cache/file_data_provider/languages-TR.txt +46 -46
  97. data/lib/i18n_data/file_data_provider.rb +0 -18
  98. data/lib/i18n_data/live_data_provider.rb +27 -30
  99. data/lib/i18n_data/version.rb +1 -1
  100. metadata +5 -5
  101. 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 svn
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 => ROOT + 'iso_3166/iso_3166.xml',
13
- :languages => ROOT + 'iso_639/iso_639.xml'
10
+ :countries => 'iso_3166/iso_3166.xml',
11
+ :languages => 'iso_639/iso_639.xml'
14
12
  }
15
13
  TRANSLATIONS = {
16
- :countries => ROOT + 'iso_3166/',
17
- :languages => ROOT + 'iso_639/'
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 => 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
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
- $stderr.puts "GET #{url}" if $DEBUG
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
- xml = get(XML_CODES[type])
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
@@ -1,3 +1,3 @@
1
1
  module I18nData
2
- VERSION = Version = "0.4.1"
2
+ VERSION = Version = "0.5.1"
3
3
  end
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.1
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-03-15 00:00:00.000000000 Z
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.0.14
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