i18n_data 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. data/CHANGELOG +2 -1
  2. data/README.markdown +6 -13
  3. data/Rakefile +10 -0
  4. data/VERSION +1 -1
  5. data/cache/file_data_provider/countries-AF.txt +3 -3
  6. data/cache/file_data_provider/countries-AM.txt +3 -3
  7. data/cache/file_data_provider/countries-AR.txt +3 -3
  8. data/cache/file_data_provider/countries-AZ.txt +3 -3
  9. data/cache/file_data_provider/countries-BE.txt +3 -3
  10. data/cache/file_data_provider/countries-BG.txt +3 -3
  11. data/cache/file_data_provider/countries-BN.txt +5 -5
  12. data/cache/file_data_provider/countries-BR.txt +15 -15
  13. data/cache/file_data_provider/countries-BS.txt +3 -3
  14. data/cache/file_data_provider/countries-CA.txt +3 -3
  15. data/cache/file_data_provider/countries-CS.txt +3 -3
  16. data/cache/file_data_provider/countries-CY.txt +3 -3
  17. data/cache/file_data_provider/countries-DA.txt +3 -3
  18. data/cache/file_data_provider/countries-DE.txt +3 -3
  19. data/cache/file_data_provider/countries-DZ.txt +3 -3
  20. data/cache/file_data_provider/countries-EL.txt +3 -3
  21. data/cache/file_data_provider/countries-EN.txt +3 -3
  22. data/cache/file_data_provider/countries-EO.txt +3 -3
  23. data/cache/file_data_provider/countries-ES.txt +3 -3
  24. data/cache/file_data_provider/countries-ET.txt +3 -3
  25. data/cache/file_data_provider/countries-EU.txt +10 -10
  26. data/cache/file_data_provider/countries-FA.txt +3 -3
  27. data/cache/file_data_provider/countries-FI.txt +3 -3
  28. data/cache/file_data_provider/countries-FO.txt +3 -3
  29. data/cache/file_data_provider/countries-FR.txt +5 -5
  30. data/cache/file_data_provider/countries-GA.txt +3 -3
  31. data/cache/file_data_provider/countries-GL.txt +3 -3
  32. data/cache/file_data_provider/countries-GU.txt +3 -3
  33. data/cache/file_data_provider/countries-HE.txt +3 -3
  34. data/cache/file_data_provider/countries-HI.txt +3 -3
  35. data/cache/file_data_provider/countries-HR.txt +3 -3
  36. data/cache/file_data_provider/countries-HU.txt +3 -3
  37. data/cache/file_data_provider/countries-HY.txt +3 -3
  38. data/cache/file_data_provider/countries-ID.txt +3 -3
  39. data/cache/file_data_provider/countries-IS.txt +3 -3
  40. data/cache/file_data_provider/countries-IT.txt +2 -2
  41. data/cache/file_data_provider/countries-JA.txt +3 -3
  42. data/cache/file_data_provider/countries-KA.txt +3 -3
  43. data/cache/file_data_provider/countries-KK.txt +55 -55
  44. data/cache/file_data_provider/countries-KM.txt +3 -3
  45. data/cache/file_data_provider/countries-KN.txt +3 -3
  46. data/cache/file_data_provider/countries-KO.txt +3 -3
  47. data/cache/file_data_provider/countries-KU.txt +3 -3
  48. data/cache/file_data_provider/countries-LT.txt +24 -24
  49. data/cache/file_data_provider/countries-LV.txt +26 -26
  50. data/cache/file_data_provider/countries-MI.txt +3 -3
  51. data/cache/file_data_provider/countries-MK.txt +3 -3
  52. data/cache/file_data_provider/countries-ML.txt +3 -3
  53. data/cache/file_data_provider/countries-MN.txt +3 -3
  54. data/cache/file_data_provider/countries-MR.txt +4 -4
  55. data/cache/file_data_provider/countries-MS.txt +3 -3
  56. data/cache/file_data_provider/countries-MT.txt +3 -3
  57. data/cache/file_data_provider/countries-NB.txt +6 -6
  58. data/cache/file_data_provider/countries-NE.txt +3 -3
  59. data/cache/file_data_provider/countries-NL.txt +4 -4
  60. data/cache/file_data_provider/countries-NN.txt +3 -3
  61. data/cache/file_data_provider/countries-OC.txt +3 -3
  62. data/cache/file_data_provider/countries-PA.txt +3 -3
  63. data/cache/file_data_provider/countries-PL.txt +6 -6
  64. data/cache/file_data_provider/countries-PS.txt +3 -3
  65. data/cache/file_data_provider/countries-PT.txt +3 -3
  66. data/cache/file_data_provider/countries-RO.txt +3 -3
  67. data/cache/file_data_provider/countries-RU.txt +46 -46
  68. data/cache/file_data_provider/countries-RW.txt +3 -3
  69. data/cache/file_data_provider/countries-SK.txt +3 -3
  70. data/cache/file_data_provider/countries-SL.txt +2 -2
  71. data/cache/file_data_provider/countries-SO.txt +3 -3
  72. data/cache/file_data_provider/countries-SQ.txt +3 -3
  73. data/cache/file_data_provider/countries-SR.txt +10 -10
  74. data/cache/file_data_provider/countries-SV.txt +3 -3
  75. data/cache/file_data_provider/countries-SW.txt +88 -88
  76. data/cache/file_data_provider/countries-TA.txt +3 -3
  77. data/cache/file_data_provider/countries-TE.txt +246 -0
  78. data/cache/file_data_provider/countries-TH.txt +3 -3
  79. data/cache/file_data_provider/countries-TI.txt +3 -3
  80. data/cache/file_data_provider/countries-TK.txt +3 -3
  81. data/cache/file_data_provider/countries-TL.txt +3 -3
  82. data/cache/file_data_provider/countries-TR.txt +3 -3
  83. data/cache/file_data_provider/countries-TT.txt +3 -3
  84. data/cache/file_data_provider/countries-UK.txt +3 -3
  85. data/cache/file_data_provider/countries-VE.txt +3 -3
  86. data/cache/file_data_provider/countries-VI.txt +3 -3
  87. data/cache/file_data_provider/countries-WA.txt +3 -3
  88. data/cache/file_data_provider/countries-WO.txt +3 -3
  89. data/cache/file_data_provider/countries-XH.txt +3 -3
  90. data/cache/file_data_provider/countries-ZU.txt +3 -3
  91. data/cache/file_data_provider/languages-AF.txt +1 -1
  92. data/cache/file_data_provider/languages-AM.txt +1 -1
  93. data/cache/file_data_provider/languages-AR.txt +1 -1
  94. data/cache/file_data_provider/languages-AZ.txt +1 -1
  95. data/cache/file_data_provider/languages-BE.txt +5 -5
  96. data/cache/file_data_provider/languages-BG.txt +1 -1
  97. data/cache/file_data_provider/languages-BR.txt +54 -54
  98. data/cache/file_data_provider/languages-BS.txt +1 -1
  99. data/cache/file_data_provider/languages-CA.txt +124 -124
  100. data/cache/file_data_provider/languages-CS.txt +5 -5
  101. data/cache/file_data_provider/languages-CY.txt +1 -1
  102. data/cache/file_data_provider/languages-DA.txt +1 -1
  103. data/cache/file_data_provider/languages-DE.txt +1 -1
  104. data/cache/file_data_provider/languages-EL.txt +1 -1
  105. data/cache/file_data_provider/languages-EN.txt +1 -1
  106. data/cache/file_data_provider/languages-EO.txt +1 -1
  107. data/cache/file_data_provider/languages-ES.txt +1 -1
  108. data/cache/file_data_provider/languages-ET.txt +1 -1
  109. data/cache/file_data_provider/languages-EU.txt +1 -1
  110. data/cache/file_data_provider/languages-FA.txt +1 -1
  111. data/cache/file_data_provider/languages-FI.txt +1 -1
  112. data/cache/file_data_provider/languages-FR.txt +1 -1
  113. data/cache/file_data_provider/languages-GA.txt +2 -2
  114. data/cache/file_data_provider/languages-GL.txt +1 -1
  115. data/cache/file_data_provider/languages-GU.txt +185 -0
  116. data/cache/file_data_provider/languages-HE.txt +1 -1
  117. data/cache/file_data_provider/languages-HI.txt +1 -1
  118. data/cache/file_data_provider/languages-HR.txt +1 -1
  119. data/cache/file_data_provider/languages-HU.txt +1 -1
  120. data/cache/file_data_provider/languages-ID.txt +2 -2
  121. data/cache/file_data_provider/languages-IS.txt +1 -1
  122. data/cache/file_data_provider/languages-IT.txt +1 -1
  123. data/cache/file_data_provider/languages-JA.txt +1 -1
  124. data/cache/file_data_provider/languages-KO.txt +1 -1
  125. data/cache/file_data_provider/languages-LT.txt +13 -13
  126. data/cache/file_data_provider/languages-LV.txt +1 -1
  127. data/cache/file_data_provider/languages-MI.txt +1 -1
  128. data/cache/file_data_provider/languages-MK.txt +1 -1
  129. data/cache/file_data_provider/languages-MN.txt +1 -1
  130. data/cache/file_data_provider/languages-MR.txt +182 -182
  131. data/cache/file_data_provider/languages-MS.txt +1 -1
  132. data/cache/file_data_provider/languages-MT.txt +1 -1
  133. data/cache/file_data_provider/languages-NB.txt +22 -22
  134. data/cache/file_data_provider/languages-NL.txt +1 -1
  135. data/cache/file_data_provider/languages-NN.txt +1 -1
  136. data/cache/file_data_provider/languages-OC.txt +1 -1
  137. data/cache/file_data_provider/languages-PA.txt +185 -0
  138. data/cache/file_data_provider/languages-PL.txt +33 -33
  139. data/cache/file_data_provider/languages-PS.txt +1 -1
  140. data/cache/file_data_provider/languages-PT.txt +1 -1
  141. data/cache/file_data_provider/languages-RO.txt +1 -1
  142. data/cache/file_data_provider/languages-RU.txt +1 -1
  143. data/cache/file_data_provider/languages-RW.txt +1 -1
  144. data/cache/file_data_provider/languages-SK.txt +1 -1
  145. data/cache/file_data_provider/languages-SL.txt +12 -12
  146. data/cache/file_data_provider/languages-SR.txt +1 -1
  147. data/cache/file_data_provider/languages-SV.txt +1 -1
  148. data/cache/file_data_provider/languages-TA.txt +171 -171
  149. data/cache/file_data_provider/languages-TH.txt +1 -1
  150. data/cache/file_data_provider/languages-TI.txt +1 -1
  151. data/cache/file_data_provider/languages-TR.txt +1 -1
  152. data/cache/file_data_provider/languages-TT.txt +1 -1
  153. data/cache/file_data_provider/languages-UK.txt +1 -1
  154. data/cache/file_data_provider/languages-VE.txt +1 -1
  155. data/cache/file_data_provider/languages-VI.txt +1 -1
  156. data/cache/file_data_provider/languages-WA.txt +1 -1
  157. data/cache/file_data_provider/languages-XH.txt +1 -1
  158. data/cache/file_data_provider/languages-ZU.txt +1 -1
  159. data/i18n_data.gemspec +4 -1
  160. data/lib/i18n_data.rb +26 -3
  161. data/lib/i18n_data/file_data_provider.rb +19 -19
  162. data/lib/i18n_data/live_data_provider.rb +24 -21
  163. data/spec/i18n_data_spec.rb +36 -0
  164. metadata +4 -1
@@ -24,7 +24,7 @@ BG;;บัลแกเรีย
24
24
  PL;;โปแลนด์
25
25
  HE;;ฮีบรู
26
26
  NA;;นาอูรู
27
- BH;;พิหาร
27
+ BH;;ภาษาปรากฤต
28
28
  MN;;มองโกเลีย
29
29
  VI;;เวียดนาม
30
30
  RW;;คินยาวันดา
@@ -24,7 +24,7 @@ BG;;ቡልጋሪኛ
24
24
  PL;;ፖሊሽ
25
25
  HE;;ዕብራስጥ
26
26
  NA;;ናኡሩ
27
- BH;;ቢሃሪ
27
+ BH;;ኮሪያኛ
28
28
  MN;;ሞንጎላዊኛ
29
29
  VI;;ቪትናምኛ
30
30
  RW;;ኪንያርዋንድኛ
@@ -24,7 +24,7 @@ BG;;Bulgarca
24
24
  PL;;Polonyaca
25
25
  HE;;İbranice
26
26
  NA;;Nauru
27
- BH;;Bihari (Hindistan)
27
+ BH;;Chamic dilleri (Malay)
28
28
  MN;;Moğol Dili
29
29
  VI;;Vietnamca
30
30
  RW;;Kinyarwanda
@@ -24,7 +24,7 @@ BG;;Bulgarça
24
24
  PL;;Polça
25
25
  HE;;Yähüdçä
26
26
  NA;;Nauruça
27
- BH;;Biharça
27
+ BH;;Ğosman telläre
28
28
  MN;;Moğolça
29
29
  VI;;Vietnamça
30
30
  RW;;Kinyarwandaça
@@ -24,7 +24,7 @@ BG;;Болгарська
24
24
  PL;;Польська
25
25
  HE;;Давньоєврейська
26
26
  NA;;Науру
27
- BH;;Біхарі
27
+ BH;;Хамітські мови
28
28
  MN;;Монгольська
29
29
  VI;;В'єтнамська
30
30
  RW;;Кіньяруанда
@@ -24,7 +24,7 @@ BG;;Bulgarian
24
24
  PL;;Polish
25
25
  HE;;Hebrew
26
26
  NA;;Nauru
27
- BH;;Bihari
27
+ BH;;Malagasy
28
28
  MN;;Mongolian
29
29
  VI;;Vietnamese
30
30
  RW;;Kinyarwanda
@@ -24,7 +24,7 @@ BG;;Tiếng Bảo Gai Lơi
24
24
  PL;;Tiếng Ba Lan
25
25
  HE;;Tiếng Do Thái
26
26
  NA;;Tiếng Nau-ru
27
- BH;;Tiếng Bi-ha-ri
27
+ BH;;Hệ ngôn ngữ Tai
28
28
  MN;;Tiếng Mông Cổ
29
29
  VI;;Tiếng Việt
30
30
  RW;;Tiếng Kin-ia-ouanh-đa
@@ -24,7 +24,7 @@ BG;;Bulgåre
24
24
  PL;;Polonès
25
25
  HE;;Ebreu
26
26
  NA;;Nawouryin
27
- BH;;Bihari
27
+ BH;;Lingaedjes toupi
28
28
  MN;;Mongol
29
29
  VI;;Vietnamyin
30
30
  RW;;Kinyarwanda
@@ -24,7 +24,7 @@ BG;;isiBulgarian
24
24
  PL;;isiPolish
25
25
  HE;;isiHebhere
26
26
  NA;;Nauru
27
- BH;;isiThai
27
+ BH;;isiBosnian
28
28
  MN;;isiMacedonian
29
29
  VI;;isiVietnamese
30
30
  RW;;Kinyarwanda
@@ -24,7 +24,7 @@ BG;;Isi-Buligariyana
24
24
  PL;;Isi-Pholishi
25
25
  HE;;Isi-Hebheru
26
26
  NA;;Nauru
27
- BH;;Isi-Thayi
27
+ BH;;Isi-Koreyani
28
28
  MN;;Isi-Makhedoniya
29
29
  VI;;Isi-Vitheyinamise
30
30
  RW;;Kinyarwanda
data/i18n_data.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{i18n_data}
8
- s.version = "0.2.4"
8
+ s.version = "0.2.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
@@ -92,6 +92,7 @@ Gem::Specification.new do |s|
92
92
  "cache/file_data_provider/countries-SV.txt",
93
93
  "cache/file_data_provider/countries-SW.txt",
94
94
  "cache/file_data_provider/countries-TA.txt",
95
+ "cache/file_data_provider/countries-TE.txt",
95
96
  "cache/file_data_provider/countries-TH.txt",
96
97
  "cache/file_data_provider/countries-TI.txt",
97
98
  "cache/file_data_provider/countries-TK.txt",
@@ -129,6 +130,7 @@ Gem::Specification.new do |s|
129
130
  "cache/file_data_provider/languages-FR.txt",
130
131
  "cache/file_data_provider/languages-GA.txt",
131
132
  "cache/file_data_provider/languages-GL.txt",
133
+ "cache/file_data_provider/languages-GU.txt",
132
134
  "cache/file_data_provider/languages-HE.txt",
133
135
  "cache/file_data_provider/languages-HI.txt",
134
136
  "cache/file_data_provider/languages-HR.txt",
@@ -150,6 +152,7 @@ Gem::Specification.new do |s|
150
152
  "cache/file_data_provider/languages-NL.txt",
151
153
  "cache/file_data_provider/languages-NN.txt",
152
154
  "cache/file_data_provider/languages-OC.txt",
155
+ "cache/file_data_provider/languages-PA.txt",
153
156
  "cache/file_data_provider/languages-PL.txt",
154
157
  "cache/file_data_provider/languages-PS.txt",
155
158
  "cache/file_data_provider/languages-PT.txt",
data/lib/i18n_data.rb CHANGED
@@ -1,16 +1,24 @@
1
1
  require 'activesupport'
2
2
 
3
3
  module I18nData
4
- VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
4
+ VERSION = File.read( File.join(File.dirname(__FILE__), '..', 'VERSION') ).strip
5
5
 
6
6
  extend self
7
7
 
8
8
  def languages(language_code='EN')
9
- data_provider.codes(:languages,language_code.to_s.upcase)
9
+ data_provider.codes(:languages, language_code.to_s.upcase)
10
10
  end
11
11
 
12
12
  def countries(language_code='EN')
13
- data_provider.codes(:countries,language_code.to_s.upcase)
13
+ data_provider.codes(:countries, language_code.to_s.upcase)
14
+ end
15
+
16
+ def country_code(name)
17
+ recognise_code(:countries, name)
18
+ end
19
+
20
+ def language_code(name)
21
+ recognise_code(:languages, name)
14
22
  end
15
23
 
16
24
  def data_provider
@@ -25,6 +33,21 @@ module I18nData
25
33
  def data_provider=(provider)
26
34
  @data_provider = provider
27
35
  end
36
+
37
+ private
38
+
39
+ def recognise_code(type, search)
40
+ search = search.strip
41
+ languages.keys.each do |code|
42
+ begin
43
+ send(type, code).each do |code, name|
44
+ return code if search == name
45
+ end
46
+ rescue NoTranslationAvailable
47
+ end
48
+ end
49
+ nil
50
+ end
28
51
 
29
52
  class NoTranslationAvailable < Exception
30
53
  def to_s
@@ -3,54 +3,54 @@ module I18nData
3
3
  DATA_SEPERATOR = ";;"
4
4
  extend self
5
5
 
6
- def codes(type,language_code)
7
- unless data = read_from_file(type,language_code)
6
+ def codes(type, language_code)
7
+ unless data = read_from_file(type, language_code)
8
8
  raise NoTranslationAvailable.new("#{type}-#{language_code}")
9
9
  end
10
10
  data
11
11
  end
12
12
 
13
13
  def write_cache(provider)
14
- languages = provider.codes(:languages,'EN').keys
15
- languages.each{|language_code|
16
- [:languages,:countries].each {|type|
14
+ languages = provider.codes(:languages, 'EN').keys
15
+ languages.each do |language_code|
16
+ [:languages, :countries].each do |type|
17
17
  begin
18
- data = provider.send(:codes,type,language_code)
19
- write_to_file(data,type,language_code)
18
+ data = provider.send(:codes, type, language_code)
19
+ write_to_file(data, type, language_code)
20
20
  rescue NoTranslationAvailable
21
21
  end
22
- }
23
- }
22
+ end
23
+ end
24
24
  end
25
25
 
26
26
  private
27
27
 
28
- def read_from_file(type,language_code)
29
- file = cache_for(type,language_code)
28
+ def read_from_file(type, language_code)
29
+ file = cache_for(type, language_code)
30
30
  return nil unless File.exist?(file)
31
31
  data = {}
32
- IO.read(file).split("\n").each{|line|
32
+ IO.read(file).split("\n").each do |line|
33
33
  code, translation = line.split(DATA_SEPERATOR)
34
34
  data[code] = translation
35
- }
35
+ end
36
36
  data
37
37
  end
38
38
 
39
- def write_to_file(data,type,language_code)
39
+ def write_to_file(data, type, language_code)
40
40
  return if data.empty?
41
- file = cache_for(type,language_code)
42
- FileUtils.mkdir_p(File.dirname(file))
41
+ file = cache_for(type, language_code)
42
+ FileUtils.mkdir_p File.dirname(file)
43
43
  File.open(file,'w') do |f|
44
- f.puts data.map{|code,translation|"#{code}#{DATA_SEPERATOR}#{translation}"} * "\n"
44
+ f.puts data.map{|code, translation| "#{code}#{DATA_SEPERATOR}#{translation}" } * "\n"
45
45
  end
46
46
  end
47
47
 
48
48
  def cache_for(type,language_code)
49
- cache("#{type}-#{language_code}")
49
+ cache "#{type}-#{language_code}"
50
50
  end
51
51
 
52
52
  def cache(file)
53
- File.join(File.dirname(__FILE__),'..','..','cache','file_data_provider',"#{file}.txt")
53
+ File.join(File.dirname(__FILE__), '..', '..', 'cache', 'file_data_provider', "#{file}.txt")
54
54
  end
55
55
  end
56
56
  end
@@ -8,60 +8,63 @@ module I18nData
8
8
  module LiveDataProvider
9
9
  extend ActiveSupport::Memoizable
10
10
  extend self
11
-
11
+
12
+ ROOT = "http://git.debian.org/?p=iso-codes/iso-codes.git;a=blob_plain;f="
13
+
12
14
  XML_CODES = {
13
- :countries => 'http://svn.debian.org/viewsvn/*checkout*/pkg-isocodes/trunk/iso-codes/iso_3166/iso_3166.xml',
14
- :languages => 'http://svn.debian.org/viewsvn/*checkout*/pkg-isocodes/trunk/iso-codes/iso_639/iso_639.xml'
15
+ :countries => ROOT + 'iso_3166/iso_3166.xml',
16
+ :languages => ROOT + 'iso_639/iso_639.xml'
15
17
  }
16
18
  TRANSLATIONS = {
17
- :languages => 'http://svn.debian.org/viewsvn/*checkout*/pkg-isocodes/trunk/iso-codes/iso_639/',
18
- :countries => 'http://svn.debian.org/viewsvn/*checkout*/pkg-isocodes/trunk/iso-codes/iso_3166/'
19
+ :countries => ROOT + 'iso_3166/',
20
+ :languages => ROOT + 'iso_639/'
19
21
  }
20
22
 
21
- def codes(type,language_code)
23
+ def codes(type, language_code)
22
24
  language_code = language_code.upcase
23
25
  if language_code == 'EN'
24
26
  send("english_#{type}")
25
27
  else
26
- translated(type,language_code)
28
+ translated(type, language_code)
27
29
  end
28
30
  end
29
31
 
30
32
  private
31
33
 
32
- def translate(type,language,to_language_code)
33
- translated = translations(type,to_language_code)[language]
34
- translated.to_s.empty? ? nil : translated
34
+ def translate(type, language, to_language_code)
35
+ translated = translations(type, to_language_code)[language]
36
+ translated.blank? ? nil : translated
35
37
  end
36
38
 
37
- def translated(type,language_code)
39
+ def translated(type, language_code)
38
40
  translations = {}
39
41
  send("english_#{type}").each do |code,name|
40
- translation = translate(type,name,language_code)
42
+ translation = translate(type, name, language_code)
41
43
  translations[code] = translation ? translation : name
42
44
  end
43
45
  translations
44
46
  end
45
47
  memoize :translated
46
48
 
47
- def translations(type,language_code)
49
+ def translations(type, language_code)
48
50
  begin
49
- data = open(TRANSLATIONS[type]+"#{language_code.downcase}.po").readlines
51
+ url = TRANSLATIONS[type]+"#{language_code.downcase}.po"
52
+ data = open(url).readlines
50
53
  rescue
51
54
  raise NoTranslationAvailable.new("for #{type} and language code = #{language_code}")
52
55
  end
53
56
 
54
- po_to_hash(data)
57
+ po_to_hash data
55
58
  end
56
59
  memoize :translations
57
60
 
58
61
  def english_languages
59
62
  codes = {}
60
63
  xml(:languages).elements.each('*/iso_639_entry') do |entry|
61
- name = entry.attributes['name'].to_s.gsub("'","\\'")
64
+ name = entry.attributes['name'].to_s.gsub("'", "\\'")
62
65
  code = entry.attributes['iso_639_1_code'].to_s.upcase
63
66
  next if code.empty? or name.empty?
64
- codes[code]=name
67
+ codes[code] = name
65
68
  end
66
69
  codes
67
70
  end
@@ -70,17 +73,17 @@ module I18nData
70
73
  def english_countries
71
74
  codes = {}
72
75
  xml(:countries).elements.each('*/iso_3166_entry') do |entry|
73
- name = entry.attributes['name'].to_s.gsub("'","\\'")
76
+ name = entry.attributes['name'].to_s.gsub("'", "\\'")
74
77
  code = entry.attributes['alpha_2_code'].to_s.upcase
75
- codes[code]=name
78
+ codes[code] = name
76
79
  end
77
80
  codes
78
81
  end
79
82
  memoize :english_countries
80
83
 
81
84
  def po_to_hash(data)
82
- names = data.select{|l| l =~ /^msgid/}.map{|line| line.match(/^msgid "(.*?)"/)[1]}
83
- translations = data.select{|l| l =~ /^msgstr/}.map{|line| line.match(/^msgstr "(.*?)"/)[1]}
85
+ names = data.select{|l| l =~ /^msgid/ }.map{|line| line.match(/^msgid "(.*?)"/)[1] }
86
+ translations = data.select{|l| l =~ /^msgstr/ }.map{|line| line.match(/^msgstr "(.*?)"/)[1] }
84
87
 
85
88
  translated = {}
86
89
  names.each_with_index do |name,index|
@@ -93,6 +93,42 @@ describe I18nData do
93
93
  end
94
94
  end
95
95
  end
96
+
97
+ describe :country_code do
98
+ before :all do
99
+ I18nData.data_provider = I18nData::FileDataProvider
100
+ end
101
+
102
+ it "recognises a countries name" do
103
+ I18nData.country_code('Germany').should == 'DE'
104
+ end
105
+
106
+ it "recognises with blanks" do
107
+ I18nData.country_code(" Germany \n\r ").should == 'DE'
108
+ end
109
+
110
+ it "returns nil when it cannot recognise" do
111
+ I18nData.country_code('XY').should == nil
112
+ end
113
+ end
114
+
115
+ describe :language_code do
116
+ before :all do
117
+ I18nData.data_provider = I18nData::FileDataProvider
118
+ end
119
+
120
+ it "recognises a countries name" do
121
+ I18nData.language_code('Deutsch').should == 'DE'
122
+ end
123
+
124
+ it "recognises with blanks" do
125
+ I18nData.language_code(" Deutsch \n\r ").should == 'DE'
126
+ end
127
+
128
+ it "returns nil when it cannot recognise" do
129
+ I18nData.language_code('XY').should == nil
130
+ end
131
+ end
96
132
  end
97
133
 
98
134
  it "has a VERSION" do
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.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
@@ -108,6 +108,7 @@ files:
108
108
  - cache/file_data_provider/countries-SV.txt
109
109
  - cache/file_data_provider/countries-SW.txt
110
110
  - cache/file_data_provider/countries-TA.txt
111
+ - cache/file_data_provider/countries-TE.txt
111
112
  - cache/file_data_provider/countries-TH.txt
112
113
  - cache/file_data_provider/countries-TI.txt
113
114
  - cache/file_data_provider/countries-TK.txt
@@ -145,6 +146,7 @@ files:
145
146
  - cache/file_data_provider/languages-FR.txt
146
147
  - cache/file_data_provider/languages-GA.txt
147
148
  - cache/file_data_provider/languages-GL.txt
149
+ - cache/file_data_provider/languages-GU.txt
148
150
  - cache/file_data_provider/languages-HE.txt
149
151
  - cache/file_data_provider/languages-HI.txt
150
152
  - cache/file_data_provider/languages-HR.txt
@@ -166,6 +168,7 @@ files:
166
168
  - cache/file_data_provider/languages-NL.txt
167
169
  - cache/file_data_provider/languages-NN.txt
168
170
  - cache/file_data_provider/languages-OC.txt
171
+ - cache/file_data_provider/languages-PA.txt
169
172
  - cache/file_data_provider/languages-PL.txt
170
173
  - cache/file_data_provider/languages-PS.txt
171
174
  - cache/file_data_provider/languages-PT.txt