i18n_data 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. data/.gitignore +3 -0
  2. data/CHANGELOG +2 -0
  3. data/README.markdown +57 -0
  4. data/Rakefile +83 -0
  5. data/VERSION +1 -0
  6. data/cache/file_data_provider/countries-AF.txt +246 -0
  7. data/cache/file_data_provider/countries-AM.txt +246 -0
  8. data/cache/file_data_provider/countries-AR.txt +246 -0
  9. data/cache/file_data_provider/countries-AZ.txt +246 -0
  10. data/cache/file_data_provider/countries-BE.txt +246 -0
  11. data/cache/file_data_provider/countries-BG.txt +246 -0
  12. data/cache/file_data_provider/countries-BN.txt +246 -0
  13. data/cache/file_data_provider/countries-BR.txt +246 -0
  14. data/cache/file_data_provider/countries-BS.txt +246 -0
  15. data/cache/file_data_provider/countries-CA.txt +246 -0
  16. data/cache/file_data_provider/countries-CS.txt +246 -0
  17. data/cache/file_data_provider/countries-CY.txt +246 -0
  18. data/cache/file_data_provider/countries-DA.txt +246 -0
  19. data/cache/file_data_provider/countries-DE.txt +246 -0
  20. data/cache/file_data_provider/countries-DZ.txt +246 -0
  21. data/cache/file_data_provider/countries-EL.txt +246 -0
  22. data/cache/file_data_provider/countries-EN.txt +246 -0
  23. data/cache/file_data_provider/countries-EO.txt +246 -0
  24. data/cache/file_data_provider/countries-ES.txt +246 -0
  25. data/cache/file_data_provider/countries-ET.txt +246 -0
  26. data/cache/file_data_provider/countries-EU.txt +246 -0
  27. data/cache/file_data_provider/countries-FA.txt +246 -0
  28. data/cache/file_data_provider/countries-FI.txt +246 -0
  29. data/cache/file_data_provider/countries-FO.txt +246 -0
  30. data/cache/file_data_provider/countries-FR.txt +246 -0
  31. data/cache/file_data_provider/countries-GA.txt +246 -0
  32. data/cache/file_data_provider/countries-GL.txt +246 -0
  33. data/cache/file_data_provider/countries-GU.txt +246 -0
  34. data/cache/file_data_provider/countries-HE.txt +246 -0
  35. data/cache/file_data_provider/countries-HI.txt +246 -0
  36. data/cache/file_data_provider/countries-HR.txt +246 -0
  37. data/cache/file_data_provider/countries-HU.txt +246 -0
  38. data/cache/file_data_provider/countries-HY.txt +246 -0
  39. data/cache/file_data_provider/countries-ID.txt +246 -0
  40. data/cache/file_data_provider/countries-IS.txt +246 -0
  41. data/cache/file_data_provider/countries-IT.txt +246 -0
  42. data/cache/file_data_provider/countries-JA.txt +246 -0
  43. data/cache/file_data_provider/countries-KA.txt +246 -0
  44. data/cache/file_data_provider/countries-KK.txt +246 -0
  45. data/cache/file_data_provider/countries-KM.txt +246 -0
  46. data/cache/file_data_provider/countries-KN.txt +246 -0
  47. data/cache/file_data_provider/countries-KO.txt +246 -0
  48. data/cache/file_data_provider/countries-KU.txt +246 -0
  49. data/cache/file_data_provider/countries-LT.txt +246 -0
  50. data/cache/file_data_provider/countries-LV.txt +246 -0
  51. data/cache/file_data_provider/countries-MI.txt +246 -0
  52. data/cache/file_data_provider/countries-MK.txt +246 -0
  53. data/cache/file_data_provider/countries-ML.txt +246 -0
  54. data/cache/file_data_provider/countries-MN.txt +246 -0
  55. data/cache/file_data_provider/countries-MR.txt +246 -0
  56. data/cache/file_data_provider/countries-MS.txt +246 -0
  57. data/cache/file_data_provider/countries-MT.txt +246 -0
  58. data/cache/file_data_provider/countries-NB.txt +246 -0
  59. data/cache/file_data_provider/countries-NE.txt +246 -0
  60. data/cache/file_data_provider/countries-NL.txt +246 -0
  61. data/cache/file_data_provider/countries-NN.txt +246 -0
  62. data/cache/file_data_provider/countries-OC.txt +246 -0
  63. data/cache/file_data_provider/countries-PA.txt +246 -0
  64. data/cache/file_data_provider/countries-PL.txt +246 -0
  65. data/cache/file_data_provider/countries-PS.txt +246 -0
  66. data/cache/file_data_provider/countries-PT.txt +246 -0
  67. data/cache/file_data_provider/countries-RO.txt +246 -0
  68. data/cache/file_data_provider/countries-RU.txt +246 -0
  69. data/cache/file_data_provider/countries-RW.txt +246 -0
  70. data/cache/file_data_provider/countries-SK.txt +246 -0
  71. data/cache/file_data_provider/countries-SL.txt +246 -0
  72. data/cache/file_data_provider/countries-SO.txt +246 -0
  73. data/cache/file_data_provider/countries-SQ.txt +246 -0
  74. data/cache/file_data_provider/countries-SR.txt +246 -0
  75. data/cache/file_data_provider/countries-SV.txt +246 -0
  76. data/cache/file_data_provider/countries-SW.txt +246 -0
  77. data/cache/file_data_provider/countries-TA.txt +246 -0
  78. data/cache/file_data_provider/countries-TH.txt +246 -0
  79. data/cache/file_data_provider/countries-TI.txt +246 -0
  80. data/cache/file_data_provider/countries-TK.txt +246 -0
  81. data/cache/file_data_provider/countries-TL.txt +246 -0
  82. data/cache/file_data_provider/countries-TR.txt +246 -0
  83. data/cache/file_data_provider/countries-TT.txt +246 -0
  84. data/cache/file_data_provider/countries-UK.txt +246 -0
  85. data/cache/file_data_provider/countries-VE.txt +246 -0
  86. data/cache/file_data_provider/countries-VI.txt +246 -0
  87. data/cache/file_data_provider/countries-WA.txt +246 -0
  88. data/cache/file_data_provider/countries-WO.txt +246 -0
  89. data/cache/file_data_provider/countries-XH.txt +246 -0
  90. data/cache/file_data_provider/countries-ZU.txt +246 -0
  91. data/cache/file_data_provider/languages-AF.txt +185 -0
  92. data/cache/file_data_provider/languages-AM.txt +185 -0
  93. data/cache/file_data_provider/languages-AR.txt +185 -0
  94. data/cache/file_data_provider/languages-AZ.txt +185 -0
  95. data/cache/file_data_provider/languages-BE.txt +185 -0
  96. data/cache/file_data_provider/languages-BG.txt +185 -0
  97. data/cache/file_data_provider/languages-BR.txt +185 -0
  98. data/cache/file_data_provider/languages-BS.txt +185 -0
  99. data/cache/file_data_provider/languages-CA.txt +185 -0
  100. data/cache/file_data_provider/languages-CS.txt +185 -0
  101. data/cache/file_data_provider/languages-CY.txt +185 -0
  102. data/cache/file_data_provider/languages-DA.txt +185 -0
  103. data/cache/file_data_provider/languages-DE.txt +185 -0
  104. data/cache/file_data_provider/languages-EL.txt +185 -0
  105. data/cache/file_data_provider/languages-EN.txt +185 -0
  106. data/cache/file_data_provider/languages-EO.txt +185 -0
  107. data/cache/file_data_provider/languages-ES.txt +185 -0
  108. data/cache/file_data_provider/languages-ET.txt +185 -0
  109. data/cache/file_data_provider/languages-EU.txt +185 -0
  110. data/cache/file_data_provider/languages-FA.txt +185 -0
  111. data/cache/file_data_provider/languages-FI.txt +185 -0
  112. data/cache/file_data_provider/languages-FR.txt +185 -0
  113. data/cache/file_data_provider/languages-GA.txt +185 -0
  114. data/cache/file_data_provider/languages-GL.txt +185 -0
  115. data/cache/file_data_provider/languages-HE.txt +185 -0
  116. data/cache/file_data_provider/languages-HI.txt +185 -0
  117. data/cache/file_data_provider/languages-HR.txt +185 -0
  118. data/cache/file_data_provider/languages-HU.txt +185 -0
  119. data/cache/file_data_provider/languages-ID.txt +185 -0
  120. data/cache/file_data_provider/languages-IS.txt +185 -0
  121. data/cache/file_data_provider/languages-IT.txt +185 -0
  122. data/cache/file_data_provider/languages-JA.txt +185 -0
  123. data/cache/file_data_provider/languages-KO.txt +185 -0
  124. data/cache/file_data_provider/languages-LT.txt +185 -0
  125. data/cache/file_data_provider/languages-LV.txt +185 -0
  126. data/cache/file_data_provider/languages-MI.txt +185 -0
  127. data/cache/file_data_provider/languages-MK.txt +185 -0
  128. data/cache/file_data_provider/languages-MN.txt +185 -0
  129. data/cache/file_data_provider/languages-MR.txt +185 -0
  130. data/cache/file_data_provider/languages-MS.txt +185 -0
  131. data/cache/file_data_provider/languages-MT.txt +185 -0
  132. data/cache/file_data_provider/languages-NB.txt +185 -0
  133. data/cache/file_data_provider/languages-NL.txt +185 -0
  134. data/cache/file_data_provider/languages-NN.txt +185 -0
  135. data/cache/file_data_provider/languages-OC.txt +185 -0
  136. data/cache/file_data_provider/languages-PL.txt +185 -0
  137. data/cache/file_data_provider/languages-PS.txt +185 -0
  138. data/cache/file_data_provider/languages-PT.txt +185 -0
  139. data/cache/file_data_provider/languages-RO.txt +185 -0
  140. data/cache/file_data_provider/languages-RU.txt +185 -0
  141. data/cache/file_data_provider/languages-RW.txt +185 -0
  142. data/cache/file_data_provider/languages-SK.txt +185 -0
  143. data/cache/file_data_provider/languages-SL.txt +185 -0
  144. data/cache/file_data_provider/languages-SR.txt +185 -0
  145. data/cache/file_data_provider/languages-SV.txt +185 -0
  146. data/cache/file_data_provider/languages-TA.txt +185 -0
  147. data/cache/file_data_provider/languages-TH.txt +185 -0
  148. data/cache/file_data_provider/languages-TI.txt +185 -0
  149. data/cache/file_data_provider/languages-TR.txt +185 -0
  150. data/cache/file_data_provider/languages-TT.txt +185 -0
  151. data/cache/file_data_provider/languages-UK.txt +185 -0
  152. data/cache/file_data_provider/languages-VE.txt +185 -0
  153. data/cache/file_data_provider/languages-VI.txt +185 -0
  154. data/cache/file_data_provider/languages-WA.txt +185 -0
  155. data/cache/file_data_provider/languages-XH.txt +185 -0
  156. data/cache/file_data_provider/languages-ZU.txt +185 -0
  157. data/example_output/all_names_for_DE.txt +85 -0
  158. data/example_output/all_names_for_FR.txt +85 -0
  159. data/example_output/all_names_for_GB.txt +85 -0
  160. data/example_output/all_names_for_US.txt +85 -0
  161. data/i18n_data.gemspec +212 -0
  162. data/lib/i18n_data/file_data_provider.rb +56 -0
  163. data/lib/i18n_data/live_data_provider.rb +97 -0
  164. data/lib/i18n_data.rb +34 -0
  165. data/spec/i18n_data/file_data_provider_spec.rb +23 -0
  166. data/spec/i18n_data/live_data_provider_spec.rb +44 -0
  167. data/spec/i18n_data_spec.rb +101 -0
  168. data/spec/spec_helper.rb +2 -0
  169. metadata +234 -0
data/i18n_data.gemspec ADDED
@@ -0,0 +1,212 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{i18n_data}
8
+ s.version = "0.2.4"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Michael Grosser"]
12
+ s.date = %q{2009-11-16}
13
+ s.email = %q{grosser.michael@gmail.com}
14
+ s.extra_rdoc_files = [
15
+ "README.markdown"
16
+ ]
17
+ s.files = [
18
+ ".gitignore",
19
+ "CHANGELOG",
20
+ "README.markdown",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "cache/file_data_provider/countries-AF.txt",
24
+ "cache/file_data_provider/countries-AM.txt",
25
+ "cache/file_data_provider/countries-AR.txt",
26
+ "cache/file_data_provider/countries-AZ.txt",
27
+ "cache/file_data_provider/countries-BE.txt",
28
+ "cache/file_data_provider/countries-BG.txt",
29
+ "cache/file_data_provider/countries-BN.txt",
30
+ "cache/file_data_provider/countries-BR.txt",
31
+ "cache/file_data_provider/countries-BS.txt",
32
+ "cache/file_data_provider/countries-CA.txt",
33
+ "cache/file_data_provider/countries-CS.txt",
34
+ "cache/file_data_provider/countries-CY.txt",
35
+ "cache/file_data_provider/countries-DA.txt",
36
+ "cache/file_data_provider/countries-DE.txt",
37
+ "cache/file_data_provider/countries-DZ.txt",
38
+ "cache/file_data_provider/countries-EL.txt",
39
+ "cache/file_data_provider/countries-EN.txt",
40
+ "cache/file_data_provider/countries-EO.txt",
41
+ "cache/file_data_provider/countries-ES.txt",
42
+ "cache/file_data_provider/countries-ET.txt",
43
+ "cache/file_data_provider/countries-EU.txt",
44
+ "cache/file_data_provider/countries-FA.txt",
45
+ "cache/file_data_provider/countries-FI.txt",
46
+ "cache/file_data_provider/countries-FO.txt",
47
+ "cache/file_data_provider/countries-FR.txt",
48
+ "cache/file_data_provider/countries-GA.txt",
49
+ "cache/file_data_provider/countries-GL.txt",
50
+ "cache/file_data_provider/countries-GU.txt",
51
+ "cache/file_data_provider/countries-HE.txt",
52
+ "cache/file_data_provider/countries-HI.txt",
53
+ "cache/file_data_provider/countries-HR.txt",
54
+ "cache/file_data_provider/countries-HU.txt",
55
+ "cache/file_data_provider/countries-HY.txt",
56
+ "cache/file_data_provider/countries-ID.txt",
57
+ "cache/file_data_provider/countries-IS.txt",
58
+ "cache/file_data_provider/countries-IT.txt",
59
+ "cache/file_data_provider/countries-JA.txt",
60
+ "cache/file_data_provider/countries-KA.txt",
61
+ "cache/file_data_provider/countries-KK.txt",
62
+ "cache/file_data_provider/countries-KM.txt",
63
+ "cache/file_data_provider/countries-KN.txt",
64
+ "cache/file_data_provider/countries-KO.txt",
65
+ "cache/file_data_provider/countries-KU.txt",
66
+ "cache/file_data_provider/countries-LT.txt",
67
+ "cache/file_data_provider/countries-LV.txt",
68
+ "cache/file_data_provider/countries-MI.txt",
69
+ "cache/file_data_provider/countries-MK.txt",
70
+ "cache/file_data_provider/countries-ML.txt",
71
+ "cache/file_data_provider/countries-MN.txt",
72
+ "cache/file_data_provider/countries-MR.txt",
73
+ "cache/file_data_provider/countries-MS.txt",
74
+ "cache/file_data_provider/countries-MT.txt",
75
+ "cache/file_data_provider/countries-NB.txt",
76
+ "cache/file_data_provider/countries-NE.txt",
77
+ "cache/file_data_provider/countries-NL.txt",
78
+ "cache/file_data_provider/countries-NN.txt",
79
+ "cache/file_data_provider/countries-OC.txt",
80
+ "cache/file_data_provider/countries-PA.txt",
81
+ "cache/file_data_provider/countries-PL.txt",
82
+ "cache/file_data_provider/countries-PS.txt",
83
+ "cache/file_data_provider/countries-PT.txt",
84
+ "cache/file_data_provider/countries-RO.txt",
85
+ "cache/file_data_provider/countries-RU.txt",
86
+ "cache/file_data_provider/countries-RW.txt",
87
+ "cache/file_data_provider/countries-SK.txt",
88
+ "cache/file_data_provider/countries-SL.txt",
89
+ "cache/file_data_provider/countries-SO.txt",
90
+ "cache/file_data_provider/countries-SQ.txt",
91
+ "cache/file_data_provider/countries-SR.txt",
92
+ "cache/file_data_provider/countries-SV.txt",
93
+ "cache/file_data_provider/countries-SW.txt",
94
+ "cache/file_data_provider/countries-TA.txt",
95
+ "cache/file_data_provider/countries-TH.txt",
96
+ "cache/file_data_provider/countries-TI.txt",
97
+ "cache/file_data_provider/countries-TK.txt",
98
+ "cache/file_data_provider/countries-TL.txt",
99
+ "cache/file_data_provider/countries-TR.txt",
100
+ "cache/file_data_provider/countries-TT.txt",
101
+ "cache/file_data_provider/countries-UK.txt",
102
+ "cache/file_data_provider/countries-VE.txt",
103
+ "cache/file_data_provider/countries-VI.txt",
104
+ "cache/file_data_provider/countries-WA.txt",
105
+ "cache/file_data_provider/countries-WO.txt",
106
+ "cache/file_data_provider/countries-XH.txt",
107
+ "cache/file_data_provider/countries-ZU.txt",
108
+ "cache/file_data_provider/languages-AF.txt",
109
+ "cache/file_data_provider/languages-AM.txt",
110
+ "cache/file_data_provider/languages-AR.txt",
111
+ "cache/file_data_provider/languages-AZ.txt",
112
+ "cache/file_data_provider/languages-BE.txt",
113
+ "cache/file_data_provider/languages-BG.txt",
114
+ "cache/file_data_provider/languages-BR.txt",
115
+ "cache/file_data_provider/languages-BS.txt",
116
+ "cache/file_data_provider/languages-CA.txt",
117
+ "cache/file_data_provider/languages-CS.txt",
118
+ "cache/file_data_provider/languages-CY.txt",
119
+ "cache/file_data_provider/languages-DA.txt",
120
+ "cache/file_data_provider/languages-DE.txt",
121
+ "cache/file_data_provider/languages-EL.txt",
122
+ "cache/file_data_provider/languages-EN.txt",
123
+ "cache/file_data_provider/languages-EO.txt",
124
+ "cache/file_data_provider/languages-ES.txt",
125
+ "cache/file_data_provider/languages-ET.txt",
126
+ "cache/file_data_provider/languages-EU.txt",
127
+ "cache/file_data_provider/languages-FA.txt",
128
+ "cache/file_data_provider/languages-FI.txt",
129
+ "cache/file_data_provider/languages-FR.txt",
130
+ "cache/file_data_provider/languages-GA.txt",
131
+ "cache/file_data_provider/languages-GL.txt",
132
+ "cache/file_data_provider/languages-HE.txt",
133
+ "cache/file_data_provider/languages-HI.txt",
134
+ "cache/file_data_provider/languages-HR.txt",
135
+ "cache/file_data_provider/languages-HU.txt",
136
+ "cache/file_data_provider/languages-ID.txt",
137
+ "cache/file_data_provider/languages-IS.txt",
138
+ "cache/file_data_provider/languages-IT.txt",
139
+ "cache/file_data_provider/languages-JA.txt",
140
+ "cache/file_data_provider/languages-KO.txt",
141
+ "cache/file_data_provider/languages-LT.txt",
142
+ "cache/file_data_provider/languages-LV.txt",
143
+ "cache/file_data_provider/languages-MI.txt",
144
+ "cache/file_data_provider/languages-MK.txt",
145
+ "cache/file_data_provider/languages-MN.txt",
146
+ "cache/file_data_provider/languages-MR.txt",
147
+ "cache/file_data_provider/languages-MS.txt",
148
+ "cache/file_data_provider/languages-MT.txt",
149
+ "cache/file_data_provider/languages-NB.txt",
150
+ "cache/file_data_provider/languages-NL.txt",
151
+ "cache/file_data_provider/languages-NN.txt",
152
+ "cache/file_data_provider/languages-OC.txt",
153
+ "cache/file_data_provider/languages-PL.txt",
154
+ "cache/file_data_provider/languages-PS.txt",
155
+ "cache/file_data_provider/languages-PT.txt",
156
+ "cache/file_data_provider/languages-RO.txt",
157
+ "cache/file_data_provider/languages-RU.txt",
158
+ "cache/file_data_provider/languages-RW.txt",
159
+ "cache/file_data_provider/languages-SK.txt",
160
+ "cache/file_data_provider/languages-SL.txt",
161
+ "cache/file_data_provider/languages-SR.txt",
162
+ "cache/file_data_provider/languages-SV.txt",
163
+ "cache/file_data_provider/languages-TA.txt",
164
+ "cache/file_data_provider/languages-TH.txt",
165
+ "cache/file_data_provider/languages-TI.txt",
166
+ "cache/file_data_provider/languages-TR.txt",
167
+ "cache/file_data_provider/languages-TT.txt",
168
+ "cache/file_data_provider/languages-UK.txt",
169
+ "cache/file_data_provider/languages-VE.txt",
170
+ "cache/file_data_provider/languages-VI.txt",
171
+ "cache/file_data_provider/languages-WA.txt",
172
+ "cache/file_data_provider/languages-XH.txt",
173
+ "cache/file_data_provider/languages-ZU.txt",
174
+ "example_output/all_names_for_DE.txt",
175
+ "example_output/all_names_for_FR.txt",
176
+ "example_output/all_names_for_GB.txt",
177
+ "example_output/all_names_for_US.txt",
178
+ "i18n_data.gemspec",
179
+ "lib/i18n_data.rb",
180
+ "lib/i18n_data/file_data_provider.rb",
181
+ "lib/i18n_data/live_data_provider.rb",
182
+ "spec/i18n_data/file_data_provider_spec.rb",
183
+ "spec/i18n_data/live_data_provider_spec.rb",
184
+ "spec/i18n_data_spec.rb",
185
+ "spec/spec_helper.rb"
186
+ ]
187
+ s.homepage = %q{http://github.com/grosser/i18n_data}
188
+ s.rdoc_options = ["--charset=UTF-8"]
189
+ s.require_paths = ["lib"]
190
+ s.rubygems_version = %q{1.3.5}
191
+ s.summary = %q{country/language names and 2-letter-code pairs, in 85 languages}
192
+ s.test_files = [
193
+ "spec/spec_helper.rb",
194
+ "spec/i18n_data/file_data_provider_spec.rb",
195
+ "spec/i18n_data/live_data_provider_spec.rb",
196
+ "spec/i18n_data_spec.rb"
197
+ ]
198
+
199
+ if s.respond_to? :specification_version then
200
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
201
+ s.specification_version = 3
202
+
203
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
204
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
205
+ else
206
+ s.add_dependency(%q<activesupport>, [">= 0"])
207
+ end
208
+ else
209
+ s.add_dependency(%q<activesupport>, [">= 0"])
210
+ end
211
+ end
212
+
@@ -0,0 +1,56 @@
1
+ module I18nData
2
+ module FileDataProvider
3
+ DATA_SEPERATOR = ";;"
4
+ extend self
5
+
6
+ def codes(type,language_code)
7
+ unless data = read_from_file(type,language_code)
8
+ raise NoTranslationAvailable.new("#{type}-#{language_code}")
9
+ end
10
+ data
11
+ end
12
+
13
+ def write_cache(provider)
14
+ languages = provider.codes(:languages,'EN').keys
15
+ languages.each{|language_code|
16
+ [:languages,:countries].each {|type|
17
+ begin
18
+ data = provider.send(:codes,type,language_code)
19
+ write_to_file(data,type,language_code)
20
+ rescue NoTranslationAvailable
21
+ end
22
+ }
23
+ }
24
+ end
25
+
26
+ private
27
+
28
+ def read_from_file(type,language_code)
29
+ file = cache_for(type,language_code)
30
+ return nil unless File.exist?(file)
31
+ data = {}
32
+ IO.read(file).split("\n").each{|line|
33
+ code, translation = line.split(DATA_SEPERATOR)
34
+ data[code] = translation
35
+ }
36
+ data
37
+ end
38
+
39
+ def write_to_file(data,type,language_code)
40
+ return if data.empty?
41
+ file = cache_for(type,language_code)
42
+ FileUtils.mkdir_p(File.dirname(file))
43
+ File.open(file,'w') do |f|
44
+ f.puts data.map{|code,translation|"#{code}#{DATA_SEPERATOR}#{translation}"} * "\n"
45
+ end
46
+ end
47
+
48
+ def cache_for(type,language_code)
49
+ cache("#{type}-#{language_code}")
50
+ end
51
+
52
+ def cache(file)
53
+ File.join(File.dirname(__FILE__),'..','..','cache','file_data_provider',"#{file}.txt")
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,97 @@
1
+ require 'open-uri'
2
+ require 'rexml/document'
3
+ gem 'activesupport', '> 2.2'
4
+ require 'activesupport'
5
+
6
+ module I18nData
7
+ # fetches data online from debian svn
8
+ module LiveDataProvider
9
+ extend ActiveSupport::Memoizable
10
+ extend self
11
+
12
+ 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
+ }
16
+ 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
+ }
20
+
21
+ def codes(type,language_code)
22
+ language_code = language_code.upcase
23
+ if language_code == 'EN'
24
+ send("english_#{type}")
25
+ else
26
+ translated(type,language_code)
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def translate(type,language,to_language_code)
33
+ translated = translations(type,to_language_code)[language]
34
+ translated.to_s.empty? ? nil : translated
35
+ end
36
+
37
+ def translated(type,language_code)
38
+ translations = {}
39
+ send("english_#{type}").each do |code,name|
40
+ translation = translate(type,name,language_code)
41
+ translations[code] = translation ? translation : name
42
+ end
43
+ translations
44
+ end
45
+ memoize :translated
46
+
47
+ def translations(type,language_code)
48
+ begin
49
+ data = open(TRANSLATIONS[type]+"#{language_code.downcase}.po").readlines
50
+ rescue
51
+ raise NoTranslationAvailable.new("for #{type} and language code = #{language_code}")
52
+ end
53
+
54
+ po_to_hash(data)
55
+ end
56
+ memoize :translations
57
+
58
+ def english_languages
59
+ codes = {}
60
+ xml(:languages).elements.each('*/iso_639_entry') do |entry|
61
+ name = entry.attributes['name'].to_s.gsub("'","\\'")
62
+ code = entry.attributes['iso_639_1_code'].to_s.upcase
63
+ next if code.empty? or name.empty?
64
+ codes[code]=name
65
+ end
66
+ codes
67
+ end
68
+ memoize :english_languages
69
+
70
+ def english_countries
71
+ codes = {}
72
+ xml(:countries).elements.each('*/iso_3166_entry') do |entry|
73
+ name = entry.attributes['name'].to_s.gsub("'","\\'")
74
+ code = entry.attributes['alpha_2_code'].to_s.upcase
75
+ codes[code]=name
76
+ end
77
+ codes
78
+ end
79
+ memoize :english_countries
80
+
81
+ 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]}
84
+
85
+ translated = {}
86
+ names.each_with_index do |name,index|
87
+ translated[name]=translations[index]
88
+ end
89
+ translated
90
+ end
91
+
92
+ def xml(type)
93
+ xml = open(XML_CODES[type]).read
94
+ REXML::Document.new(xml)
95
+ end
96
+ end
97
+ end
data/lib/i18n_data.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'activesupport'
2
+
3
+ module I18nData
4
+ VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
5
+
6
+ extend self
7
+
8
+ def languages(language_code='EN')
9
+ data_provider.codes(:languages,language_code.to_s.upcase)
10
+ end
11
+
12
+ def countries(language_code='EN')
13
+ data_provider.codes(:countries,language_code.to_s.upcase)
14
+ end
15
+
16
+ def data_provider
17
+ if @data_provider
18
+ @data_provider
19
+ else
20
+ require 'i18n_data/file_data_provider'
21
+ FileDataProvider
22
+ end
23
+ end
24
+
25
+ def data_provider=(provider)
26
+ @data_provider = provider
27
+ end
28
+
29
+ class NoTranslationAvailable < Exception
30
+ def to_s
31
+ "NoTranslationAvailable -- #{super}"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ require File.join(File.dirname(__FILE__),'..',"spec_helper")
2
+ require 'i18n_data/file_data_provider'
3
+
4
+ describe I18nData::FileDataProvider do
5
+ before do
6
+ `rm -f #{I18nData::FileDataProvider.send(:cache_for,"XX","YY")}`
7
+ end
8
+
9
+ def read(x,y)
10
+ I18nData::FileDataProvider.codes(x,y)
11
+ end
12
+
13
+ it "preserves data when writing and then reading" do
14
+ data = {"x"=>"y","z"=>"w"}
15
+ I18nData::FileDataProvider.send(:write_to_file,data,"XX","YY")
16
+ read("XX","YY").should == data
17
+ end
18
+
19
+ it "does not write empty data sets" do
20
+ I18nData::FileDataProvider.send(:write_to_file,{},"XX","YY")
21
+ lambda{read("XX","YY")}.should raise_error I18nData::NoTranslationAvailable
22
+ end
23
+ end
@@ -0,0 +1,44 @@
1
+ require File.join(File.dirname(__FILE__),'..',"spec_helper")
2
+ require 'i18n_data/live_data_provider'
3
+
4
+ describe I18nData::LiveDataProvider do
5
+ describe :po_to_hash do
6
+ def po_to_hash(text)
7
+ I18nData::LiveDataProvider.send(:po_to_hash,text)
8
+ end
9
+
10
+ it "parses po file into translations" do
11
+ text = <<EOF
12
+ # come comment msgstr
13
+ msgid "one"
14
+ msgstr "1"
15
+ EOF
16
+ po_to_hash(text).should == {"one"=>"1"}
17
+ end
18
+
19
+ it "keeps order of translations" do
20
+ text = <<EOF
21
+ msgid "one"
22
+ msgstr "1"
23
+ msgid "two"
24
+ msgstr ""
25
+ msgid "three"
26
+ msgstr "3"
27
+ EOF
28
+ po_to_hash(text).should == {"one"=>"1","two"=>"","three"=>"3"}
29
+ end
30
+
31
+ it "finds x-line long translations" do
32
+ pending
33
+ text = <<EOF
34
+ #. name for chu, cu
35
+ msgid ""
36
+ "Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church "
37
+ "Slavonic"
38
+ msgstr "Kirchenslavisch"
39
+ EOF
40
+ long_name = "Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic"
41
+ po_to_hash(text)[long_name].should == "Kirchenslavisch"
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,101 @@
1
+ require File.expand_path("spec_helper", File.dirname(__FILE__))
2
+
3
+ NUM_2_LETTER_LANGUAGES = 185
4
+ NUM_COUNTRIES = 246
5
+
6
+ describe I18nData do
7
+ require "i18n_data/live_data_provider"
8
+ require "i18n_data/file_data_provider"
9
+
10
+ [I18nData::LiveDataProvider,I18nData::FileDataProvider].each do |provider|
11
+ describe "using #{provider}" do
12
+ before :all do
13
+ I18nData.data_provider = provider
14
+ end
15
+
16
+ describe :languages do
17
+ it "raises NoTranslationAvailable for unavailable languages" do
18
+ lambda{I18nData.languages('XX')}.should raise_error(I18nData::NoTranslationAvailable)
19
+ end
20
+
21
+ describe :english do
22
+ it "does not contain blanks" do
23
+ I18nData.languages.detect {|k,v| k.blank? or v.blank?}.should == nil
24
+ end
25
+
26
+ it "has english as default" do
27
+ I18nData.languages['DE'].should == 'German'
28
+ end
29
+
30
+ it "contains all languages" do
31
+ I18nData.languages.size.should == NUM_2_LETTER_LANGUAGES
32
+ end
33
+ end
34
+
35
+ describe :translated do
36
+ it "is translated" do
37
+ I18nData.languages('DE')['DE'].should == 'Deutsch'
38
+ end
39
+
40
+ it "contains all languages" do
41
+ I18nData.languages('DE').size.should == NUM_2_LETTER_LANGUAGES
42
+ end
43
+
44
+ it "has english names for not-translateable languages" do
45
+ I18nData.languages('IS')['HA'].should == I18nData.languages['HA']
46
+ end
47
+
48
+ it "does not contain blanks" do
49
+ I18nData.languages('GL').detect {|k,v| k.blank? or v.blank?}.should == nil
50
+ end
51
+
52
+ it "is written in unicode" do
53
+ I18nData.languages('DE')['DA'].should == 'Dänisch'
54
+ end
55
+ end
56
+ end
57
+
58
+ describe :countries do
59
+ describe :english do
60
+ it "has english as default" do
61
+ I18nData.countries['DE'].should == 'Germany'
62
+ end
63
+
64
+ it "does not contain blanks" do
65
+ I18nData.countries.detect {|k,v| k.blank? or v.blank?}.should == nil
66
+ end
67
+
68
+ it "contains all countries" do
69
+ I18nData.countries.size.should == NUM_COUNTRIES
70
+ end
71
+ end
72
+
73
+ describe :translated do
74
+ it "is translated" do
75
+ I18nData.countries('DE')['DE'].should == 'Deutschland'
76
+ end
77
+
78
+ it "contains all countries" do
79
+ I18nData.countries('DE').size.should == NUM_COUNTRIES
80
+ end
81
+
82
+ it "has english names for not-translateable countries" do
83
+ I18nData.countries('IS')['PK'].should == I18nData.countries['PK']
84
+ end
85
+
86
+ it "does not contain blanks" do
87
+ I18nData.countries('GL').detect {|k,v| k.blank? or v.blank?}.should == nil
88
+ end
89
+
90
+ it "is written in unicode" do
91
+ I18nData.countries('DE')['DK'].should == 'Dänemark'
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ it "has a VERSION" do
99
+ I18nData::VERSION.should =~ /^\d+\.\d+\.\d+$/
100
+ end
101
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH << 'lib'
2
+ require 'i18n_data'