sundawg_country_codes 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +5 -2
- data/README.rdoc +116 -0
- data/Rakefile +2 -2
- data/lib/language_iso_translater.rb +30 -0
- data/lib/languages.yml +750 -0
- data/lib/usa_state_translater.rb +2 -2
- data/sundawg_country_codes.gemspec +10 -10
- data/test/country_iso_translater_test.rb +4 -4
- data/test/language_iso_translater_test.rb +41 -0
- metadata +30 -11
- data/README +0 -98
data/Manifest
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
-
|
2
|
-
README
|
1
|
+
README.rdoc
|
3
2
|
Rakefile
|
4
3
|
lib/countries.yml
|
5
4
|
lib/country_iso_translater.rb
|
5
|
+
lib/language_iso_translater.rb
|
6
|
+
lib/languages.yml
|
6
7
|
lib/usa_state_translater.rb
|
7
8
|
lib/usa_states.yml
|
8
9
|
sundawg_country_codes.gemspec
|
9
10
|
test/country_iso_translater_test.rb
|
11
|
+
test/language_iso_translater_test.rb
|
10
12
|
test/test_helper.rb
|
11
13
|
test/usa_translater_test.rb
|
14
|
+
Manifest
|
data/README.rdoc
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
= SunDawg Country Codes
|
2
|
+
|
3
|
+
== About
|
4
|
+
|
5
|
+
This project is a Ruby gem to manage ISO 3166 country names and their corresponding alpha-2 and alpha-3 codes. Additional support has been added for ISO 4127 currency information and standard conventions for states in the USA (based on the the 3166-2:US code).
|
6
|
+
|
7
|
+
Reference information can be found:
|
8
|
+
|
9
|
+
ISO 3166 Country Codes
|
10
|
+
|
11
|
+
http://en.wikipedia.org/wiki/ISO_3166-1
|
12
|
+
|
13
|
+
ISO 4217 Currency Information
|
14
|
+
|
15
|
+
http://www.xe.com/iso4217.php
|
16
|
+
http://www.xe.com/symbols.php
|
17
|
+
|
18
|
+
ISO 3166-2:US Codes
|
19
|
+
|
20
|
+
http://code.google.com/apis/chart/statecodes.html
|
21
|
+
http://en.wikipedia.org/wiki/ISO_3166-2:US
|
22
|
+
|
23
|
+
ISO 639 Languages
|
24
|
+
|
25
|
+
http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
|
26
|
+
|
27
|
+
== Testing
|
28
|
+
|
29
|
+
Tests can be executed by running:
|
30
|
+
|
31
|
+
rake test
|
32
|
+
|
33
|
+
== Code Examples
|
34
|
+
|
35
|
+
To translate from a country's name to their ISO Alpha-2 code:
|
36
|
+
|
37
|
+
SunDawg::CountryIsoTranslater.translate_iso3166_name_to_alpha2("United States")
|
38
|
+
|
39
|
+
To translate from a country's name to their ISO Alpha-3 code:
|
40
|
+
|
41
|
+
SunDawg::CountryIsoTranslater.translate_iso3166_name_to_alpha3("Egypt")
|
42
|
+
|
43
|
+
To translate from a country's ISO Alpha-2 code to country name:
|
44
|
+
|
45
|
+
SunDawg::CountryIsoTranslater.translate_iso3166_alpha2_to_name("US")
|
46
|
+
|
47
|
+
To translate form a country's ISO Alpha-3 code to country name:
|
48
|
+
|
49
|
+
SunDawg::CountryIsoTranslater.translate_iso3166_alpha3_to_name("ESP")
|
50
|
+
|
51
|
+
To obtain currency information for a country:
|
52
|
+
|
53
|
+
currency = SunDawg::CountryIsoTranslater.get_iso4217_currency_by_iso3166_alpha2("US")
|
54
|
+
assert_equal currency["code"], "USD"
|
55
|
+
assert_equal currency["symbol"], "$"
|
56
|
+
assert_equal currency["name"], "Dollars"
|
57
|
+
assert_equal currency["unicode_hex"], 36
|
58
|
+
|
59
|
+
NOTE:
|
60
|
+
|
61
|
+
Not all countries have currency information and not all currency information contains both the symbol. Some currency information contain a second currency under currency["alt_currency"] which will then contain the same hash values for a currency.
|
62
|
+
|
63
|
+
Furthermore, while the hex value for representing the unicode symbol is stored in the .yml file, the import into Ruby is converting it into decimal. You can convert back to hex as so:
|
64
|
+
|
65
|
+
assert_equal currency["unicode_hex"].to_s(16), "24"
|
66
|
+
|
67
|
+
The unicode value, either in base 10 or base 16 will allow you to render the symbol properly in HTML:
|
68
|
+
|
69
|
+
$ or $
|
70
|
+
|
71
|
+
More information:
|
72
|
+
|
73
|
+
http://www.fileformat.info/info/unicode/char/0024/index.htm
|
74
|
+
|
75
|
+
To build the unicode HTML for a symbol:
|
76
|
+
|
77
|
+
currency = SunDawg::CountryIsoTranslater.get_iso4217_currency_by_iso3166_alpha2("UZ")
|
78
|
+
assert_equal SunDawg::CountryIsoTranslater.build_html_unicode(currency["unicode_hex"]), "лв"
|
79
|
+
|
80
|
+
To translate to and from USA state name and the 2-digit code:
|
81
|
+
|
82
|
+
SunDawg::USAStateTranslater.translate_name_to_code('New York')
|
83
|
+
SunDawg::USAStateTranslater.translate_code_to_name('NY')
|
84
|
+
|
85
|
+
To translate ISO-639 languages from alpha 2 code:
|
86
|
+
|
87
|
+
language = SunDawg::LanguageIsoTranslater.get_iso_639_1_translation("en")
|
88
|
+
assert_equal "English", language['name']
|
89
|
+
assert_equal "eng", language['alpha3t']
|
90
|
+
|
91
|
+
NOTE: Some languages have an alternate alpha3b code per ISO-639-2/B to indicate the "B" alpha 3 letter code for the language.
|
92
|
+
|
93
|
+
== Data Files
|
94
|
+
|
95
|
+
All country code and names are stored in a countries.yml file that can be changed as you need. The latest codes and country names are derived from:
|
96
|
+
|
97
|
+
http://en.wikipedia.org/wiki/ISO_3166-1
|
98
|
+
|
99
|
+
== Gem Install
|
100
|
+
|
101
|
+
This gem is hosted on rubygems.org.
|
102
|
+
|
103
|
+
http://rubygems.org/gems/sundawg_country_codes
|
104
|
+
|
105
|
+
== Rails Install
|
106
|
+
|
107
|
+
To include this gem in your Rails project, add the following to your config/environment.rb:
|
108
|
+
|
109
|
+
config.gem 'sundawg_country_codes', :lib => 'country_iso_translater'
|
110
|
+
|
111
|
+
== History
|
112
|
+
v0.0.4 - Added ISO 639 Language translater, cleaned up documents.
|
113
|
+
v0.0.3 - Added USA State translater and cleaned up unit tests.
|
114
|
+
v0.0.2b - Completed all currency information, unicode HTML utility, and bug fixes. Gem version re-published as 0.0.2.
|
115
|
+
v0.0.2 - Added ISO 4217 currency information.
|
116
|
+
v0.0.1 - Allows basic ISO 3166 translation.
|
data/Rakefile
CHANGED
@@ -3,8 +3,8 @@ require 'rubygems'
|
|
3
3
|
require 'rake'
|
4
4
|
require 'echoe'
|
5
5
|
|
6
|
-
Echoe.new('sundawg_country_codes', '0.0.
|
7
|
-
p.description = "Manage ISO 3166 Country Names and Codes."
|
6
|
+
Echoe.new('sundawg_country_codes', '0.0.4') do |p|
|
7
|
+
p.description = "Manage ISO 3166 Country Names and Codes, ISO 639 Languages, and ISO 4217 Currencies."
|
8
8
|
p.url = "http://github.com/SunDawg/country_codes"
|
9
9
|
p.author = "Christopher Sun"
|
10
10
|
p.email = "christopher.sun@gmail.com"
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# manages language ISO-639 information
|
2
|
+
# http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
|
3
|
+
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module SunDawg
|
7
|
+
module LanguageIsoTranslater
|
8
|
+
# allows client application to override YAML hash
|
9
|
+
FILE = File.expand_path(File.join(File.dirname(__FILE__), 'languages.yml')) unless defined?(FILE)
|
10
|
+
LANGUAGES = YAML.load_file(FILE) unless defined?(LANGUAGES)
|
11
|
+
|
12
|
+
# O(1) fetch of language properties given the ISO_639_1 2-letter code
|
13
|
+
def self.get_iso_639_1_translation(code)
|
14
|
+
raise NoLanguageError.new("[#{code}] IS NOT VALID") if LANGUAGES[code].nil?
|
15
|
+
LANGUAGES[code]
|
16
|
+
end
|
17
|
+
|
18
|
+
class NoLanguageError < StandardError
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Needed to process "no" for Norwegian. It is a reserved word in YAML :/.
|
24
|
+
SunDawg::LanguageIsoTranslater::LANGUAGES.keys.each do |k|
|
25
|
+
if k.size > 2
|
26
|
+
v = SunDawg::LanguageIsoTranslater::LANGUAGES[k]
|
27
|
+
SunDawg::LanguageIsoTranslater::LANGUAGES.delete(k)
|
28
|
+
SunDawg::LanguageIsoTranslater::LANGUAGES[k[2..3]] = v
|
29
|
+
end
|
30
|
+
end
|
data/lib/languages.yml
ADDED
@@ -0,0 +1,750 @@
|
|
1
|
+
ab:
|
2
|
+
name: Abkhaz
|
3
|
+
family: Northwest Caucasian
|
4
|
+
alpha3t: abk
|
5
|
+
aa:
|
6
|
+
name: Afar
|
7
|
+
family: Afro-Asiatic
|
8
|
+
alpha3t: aar
|
9
|
+
af:
|
10
|
+
name: Afrikaans
|
11
|
+
family: Indo-European
|
12
|
+
alpha3t: afr
|
13
|
+
ak:
|
14
|
+
name: Akan
|
15
|
+
family: Niger-Congo
|
16
|
+
alpha3t: aka
|
17
|
+
sq:
|
18
|
+
name: Albanian
|
19
|
+
family: Indo-European
|
20
|
+
alpha3t: sqi
|
21
|
+
am:
|
22
|
+
name: Amharic
|
23
|
+
family: Afro-Asiatic
|
24
|
+
alpha3t: amh
|
25
|
+
ar:
|
26
|
+
name: Arabic
|
27
|
+
family: Afro-Asiatic
|
28
|
+
alpha3t: ara
|
29
|
+
an:
|
30
|
+
name: Aragonese
|
31
|
+
family: Indo-European
|
32
|
+
alpha3t: arg
|
33
|
+
hy:
|
34
|
+
name: Armenian
|
35
|
+
family: Indo-European
|
36
|
+
alpha3t: hye
|
37
|
+
as:
|
38
|
+
name: Assamese
|
39
|
+
family: Indo-European
|
40
|
+
alpha3t: asm
|
41
|
+
av:
|
42
|
+
name: Avaric
|
43
|
+
family: Northeast Caucasian
|
44
|
+
alpha3t: ava
|
45
|
+
ae:
|
46
|
+
name: Avestan
|
47
|
+
family: Indo-European
|
48
|
+
alpha3t: ave
|
49
|
+
ay:
|
50
|
+
name: Aymara
|
51
|
+
family: Aymaran
|
52
|
+
alpha3t: aym
|
53
|
+
az:
|
54
|
+
name: Azerbaijani
|
55
|
+
family: Turkic
|
56
|
+
alpha3t: aze
|
57
|
+
bm:
|
58
|
+
name: Bambara
|
59
|
+
family: Niger-Congo
|
60
|
+
alpha3t: bam
|
61
|
+
ba:
|
62
|
+
name: Bashkir
|
63
|
+
family: Turkic
|
64
|
+
alpha3t: bak
|
65
|
+
eu:
|
66
|
+
name: Baque
|
67
|
+
family: Language Isolate
|
68
|
+
alpha3t: eus
|
69
|
+
alpha3b: baq
|
70
|
+
be:
|
71
|
+
name: Belarusian
|
72
|
+
family: Indo-European
|
73
|
+
alpha3t: bel
|
74
|
+
bn:
|
75
|
+
name: Bengali
|
76
|
+
family: Indo-European
|
77
|
+
alpha3t: ben
|
78
|
+
bh:
|
79
|
+
name: Bihari
|
80
|
+
family: Indo-European
|
81
|
+
alpha3t: bih
|
82
|
+
bi:
|
83
|
+
name: Bislama
|
84
|
+
family: Creole
|
85
|
+
alpha3t: bis
|
86
|
+
bs:
|
87
|
+
name: Bosnian
|
88
|
+
family: Indo-European
|
89
|
+
alpha3t: bos
|
90
|
+
br:
|
91
|
+
name: Breton
|
92
|
+
family: Indo-European
|
93
|
+
alpha3t: bre
|
94
|
+
bg:
|
95
|
+
name: Bulgarian
|
96
|
+
family: Indo-European
|
97
|
+
alpha3t: bul
|
98
|
+
my:
|
99
|
+
name: Burmese
|
100
|
+
family: Sino-Tibetan
|
101
|
+
alpha3t: mya
|
102
|
+
alpha3b: bur
|
103
|
+
ca:
|
104
|
+
name: Catalan
|
105
|
+
family: Indo-European
|
106
|
+
alpha3t: cat
|
107
|
+
ch:
|
108
|
+
name: Chamorro
|
109
|
+
family: Austronesian
|
110
|
+
alpha3t: cha
|
111
|
+
ce:
|
112
|
+
name: Chechen
|
113
|
+
family: Northeast Caucasian
|
114
|
+
alpha3t: che
|
115
|
+
ny:
|
116
|
+
name: Chichewa
|
117
|
+
family: Niger-Congo
|
118
|
+
alpha3t: nya
|
119
|
+
zh:
|
120
|
+
name: Chinese
|
121
|
+
family: Sino-Tibetan
|
122
|
+
alpha3t: zho
|
123
|
+
alpha3b: chi
|
124
|
+
cv:
|
125
|
+
name: Chuvash
|
126
|
+
family: Turkic
|
127
|
+
alpha3t: chv
|
128
|
+
kw:
|
129
|
+
name: Cornish
|
130
|
+
family: Indo-European
|
131
|
+
alpha3t: cor
|
132
|
+
co:
|
133
|
+
name: Corsican
|
134
|
+
family: Indo-European
|
135
|
+
alpha3t: cos
|
136
|
+
cr:
|
137
|
+
name: Cree
|
138
|
+
family: Algonquian
|
139
|
+
alpha3t: cre
|
140
|
+
hr:
|
141
|
+
name: Croatian
|
142
|
+
family: Indo-European
|
143
|
+
alpha3t: hrv
|
144
|
+
cs:
|
145
|
+
name: Czech
|
146
|
+
family: Indo-European
|
147
|
+
alpha3t: ces
|
148
|
+
alpha3b: cze
|
149
|
+
da:
|
150
|
+
name: Danish
|
151
|
+
family: Indo-European
|
152
|
+
alpha3t: dan
|
153
|
+
dv:
|
154
|
+
name: Divehi
|
155
|
+
family: Indo-European
|
156
|
+
alpha3t: div
|
157
|
+
nl:
|
158
|
+
name: Dutch
|
159
|
+
family: Indo-European
|
160
|
+
alpha3t: nld
|
161
|
+
alpha3b: dut
|
162
|
+
dz:
|
163
|
+
name: Dzongkha
|
164
|
+
family: Sino-Tibetan
|
165
|
+
alpha3t: dzo
|
166
|
+
en:
|
167
|
+
name: English
|
168
|
+
family: Indo-European
|
169
|
+
alpha3t: eng
|
170
|
+
eo:
|
171
|
+
name: Esperanto
|
172
|
+
family: Constructed
|
173
|
+
alpha3t: epo
|
174
|
+
et:
|
175
|
+
name: Estonian
|
176
|
+
family: Finno-Ugric
|
177
|
+
alpha3t: est
|
178
|
+
ee:
|
179
|
+
name: Ewe
|
180
|
+
family: Niger-Congo
|
181
|
+
alpha3t: ewe
|
182
|
+
fo:
|
183
|
+
name: Faroese
|
184
|
+
family: Indo-European
|
185
|
+
alpha3t: fao
|
186
|
+
fj:
|
187
|
+
name: Fijian
|
188
|
+
family: Austronesian
|
189
|
+
alpha3t: fij
|
190
|
+
fi:
|
191
|
+
name: Finnish
|
192
|
+
family: Finno-Ugric
|
193
|
+
alpha3t: fin
|
194
|
+
fr:
|
195
|
+
name: French
|
196
|
+
family: Indo-European
|
197
|
+
alpha3t: fra
|
198
|
+
alpha3b: fre
|
199
|
+
ff:
|
200
|
+
name: Fula
|
201
|
+
family: Niger-Congo
|
202
|
+
alpha3t: ful
|
203
|
+
gl:
|
204
|
+
name: Galican
|
205
|
+
family: Indo-European
|
206
|
+
alpha3t: glg
|
207
|
+
ka:
|
208
|
+
name: Georgian
|
209
|
+
family: South Caucasian
|
210
|
+
alpha3t: kat
|
211
|
+
alpha3b: geo
|
212
|
+
de:
|
213
|
+
name: German
|
214
|
+
family: Indo-European
|
215
|
+
alpha3t: deu
|
216
|
+
alpha3b: ger
|
217
|
+
el:
|
218
|
+
name: Greek
|
219
|
+
family: Indo-European
|
220
|
+
alpha3t: ell
|
221
|
+
alpha3b: gre
|
222
|
+
gn:
|
223
|
+
name: Guarani
|
224
|
+
family: Tupi-Guarani
|
225
|
+
alpha3t: grn
|
226
|
+
gu:
|
227
|
+
name: Gujarati
|
228
|
+
family: Indo-European
|
229
|
+
alpha3t: guj
|
230
|
+
ht:
|
231
|
+
name: Haitian
|
232
|
+
family: Creole
|
233
|
+
alpha3t: hat
|
234
|
+
ha:
|
235
|
+
name: Hausa
|
236
|
+
family: Afro-Asiatic
|
237
|
+
alpha3t: hau
|
238
|
+
he:
|
239
|
+
name: Hebrew
|
240
|
+
family: Afro-Asiatic
|
241
|
+
alpha3t: heb
|
242
|
+
hz:
|
243
|
+
name: Herero
|
244
|
+
family: Niger-Congo
|
245
|
+
alpha3t: her
|
246
|
+
hi:
|
247
|
+
name: Hindi
|
248
|
+
family: Indo-European
|
249
|
+
alpha3t: hin
|
250
|
+
ho:
|
251
|
+
name: Hiri Motu
|
252
|
+
family: Austronesian
|
253
|
+
alpha3t: hmo
|
254
|
+
hu:
|
255
|
+
name: Hungarian
|
256
|
+
family: Finno-Ugric
|
257
|
+
alpha3t: hun
|
258
|
+
ia:
|
259
|
+
name: Interlingua
|
260
|
+
family: Constructed
|
261
|
+
alpha3t: ina
|
262
|
+
id:
|
263
|
+
name: Indonesian
|
264
|
+
family: Austronesian
|
265
|
+
alpha3t: ind
|
266
|
+
ie:
|
267
|
+
name: Interlingue
|
268
|
+
family: Constructed
|
269
|
+
alpha3t: ile
|
270
|
+
ga:
|
271
|
+
name: Irish
|
272
|
+
family: Indo-European
|
273
|
+
alpha3t: gle
|
274
|
+
ig:
|
275
|
+
name: Igbo
|
276
|
+
family: Niger-Congo
|
277
|
+
alpha3t: ibo
|
278
|
+
ik:
|
279
|
+
name: Inupiaq
|
280
|
+
family: Eskimo-Aleut
|
281
|
+
alpha3t: ipk
|
282
|
+
io:
|
283
|
+
name: Ido
|
284
|
+
family: Constructed
|
285
|
+
alpha3t: ido
|
286
|
+
is:
|
287
|
+
name: Icelandic
|
288
|
+
family: Indo-European
|
289
|
+
alpha3t: isl
|
290
|
+
alpha3b: ice
|
291
|
+
it:
|
292
|
+
name: Italian
|
293
|
+
family: Indo-European
|
294
|
+
alpha3t: ita
|
295
|
+
iu:
|
296
|
+
name: Inuktitut
|
297
|
+
family: Eskimo-Aleut
|
298
|
+
alpha3t: iku
|
299
|
+
ja:
|
300
|
+
name: Japanese
|
301
|
+
family: Japonic
|
302
|
+
alpha3t: jpn
|
303
|
+
jv:
|
304
|
+
name: Javanese
|
305
|
+
family: Austronesian
|
306
|
+
alpha3t: jav
|
307
|
+
kl:
|
308
|
+
name: Kalaallisut
|
309
|
+
family: Eskimo-Aleut
|
310
|
+
alpha3t: kal
|
311
|
+
kn:
|
312
|
+
name: Kannada
|
313
|
+
family: Dravidian
|
314
|
+
alpha3t: kan
|
315
|
+
kr:
|
316
|
+
name: Kanuri
|
317
|
+
family: Nilo-Saharan
|
318
|
+
alpha3t: kau
|
319
|
+
ks:
|
320
|
+
name: Kashmiri
|
321
|
+
family: Indo-European
|
322
|
+
alpha3t: kas
|
323
|
+
kk:
|
324
|
+
name: Kazakh
|
325
|
+
family: Turkic
|
326
|
+
alpha3t: kaz
|
327
|
+
km:
|
328
|
+
name: Khmer
|
329
|
+
family: Austro-Asiatic
|
330
|
+
alpha3t: khm
|
331
|
+
ki:
|
332
|
+
name: Kikuyu
|
333
|
+
family: Niger-Congo
|
334
|
+
alpha3t: kik
|
335
|
+
rw:
|
336
|
+
name: Kinyarwanda
|
337
|
+
family: Niger-Congo
|
338
|
+
alpha3t: kin
|
339
|
+
ky:
|
340
|
+
name: Kirghiz
|
341
|
+
family: Turkic
|
342
|
+
alpha3t: kir
|
343
|
+
kv:
|
344
|
+
name: Komi
|
345
|
+
family: Finno-Ugric
|
346
|
+
alpha3t: kom
|
347
|
+
kg:
|
348
|
+
name: Kongo
|
349
|
+
family: Niger-Congo
|
350
|
+
alpha3t: kon
|
351
|
+
ko:
|
352
|
+
name: Korean
|
353
|
+
family: Language Isolate
|
354
|
+
alpha3t: kor
|
355
|
+
ku:
|
356
|
+
name: Kurdish
|
357
|
+
family: Indo-European
|
358
|
+
alpha3t: kur
|
359
|
+
kj:
|
360
|
+
name: Kwanyama
|
361
|
+
family: Niger-Congo
|
362
|
+
alpha3t: kua
|
363
|
+
la:
|
364
|
+
name: Latin
|
365
|
+
family: Indo-European
|
366
|
+
alpha3t: lat
|
367
|
+
lb:
|
368
|
+
name: Luxembourgish
|
369
|
+
family: Indo-European
|
370
|
+
alpha3t: ltz
|
371
|
+
lg:
|
372
|
+
name: Luganda
|
373
|
+
family: Niger-Congo
|
374
|
+
alpha3t: lug
|
375
|
+
li:
|
376
|
+
name: Limburgish
|
377
|
+
family: Indo-European
|
378
|
+
alpha3t: lim
|
379
|
+
ln:
|
380
|
+
name: Lingala
|
381
|
+
family: Niger-Congo
|
382
|
+
alpha3t: lin
|
383
|
+
lo:
|
384
|
+
name: Lao
|
385
|
+
family: Tai-Kadai
|
386
|
+
alpha3t: lao
|
387
|
+
lt:
|
388
|
+
name: Lithuanian
|
389
|
+
family: Indo-European
|
390
|
+
alpha3t: lit
|
391
|
+
lu:
|
392
|
+
name: Luba-Katanga
|
393
|
+
family: Niger-Congo
|
394
|
+
alpha3t: lub
|
395
|
+
lv:
|
396
|
+
name: Latvian
|
397
|
+
family: Indo-European
|
398
|
+
alpha3t: lav
|
399
|
+
gv:
|
400
|
+
name: Manx
|
401
|
+
family: Indo-European
|
402
|
+
alpha3t: glv
|
403
|
+
mk:
|
404
|
+
name: Macedonian
|
405
|
+
family: Indo-European
|
406
|
+
alpha3t: mkd
|
407
|
+
alpha3b: mac
|
408
|
+
mg:
|
409
|
+
name: Malagasy
|
410
|
+
family: Austronesian
|
411
|
+
alpha3t: mlg
|
412
|
+
ms:
|
413
|
+
name: Malay
|
414
|
+
family: Austronesian
|
415
|
+
alpha3t: msa
|
416
|
+
alpha3b: may
|
417
|
+
ml:
|
418
|
+
name: Malayalam
|
419
|
+
family: Dravidian
|
420
|
+
alpha3t: mal
|
421
|
+
mt:
|
422
|
+
name: Maltese
|
423
|
+
family: Afro-Asiatic
|
424
|
+
alpha3t: mlt
|
425
|
+
mi:
|
426
|
+
name: Māori
|
427
|
+
family: Austronesian
|
428
|
+
alpha3t: mri
|
429
|
+
alpha3b: mao
|
430
|
+
mr:
|
431
|
+
name: Marathi
|
432
|
+
family: Indo-European
|
433
|
+
alpha3t: mar
|
434
|
+
mh:
|
435
|
+
name: Marshallese
|
436
|
+
family: Austronesian
|
437
|
+
alpha3t: mah
|
438
|
+
mn:
|
439
|
+
name: Mongolian
|
440
|
+
family: Mongolic
|
441
|
+
alpha3t: mon
|
442
|
+
na:
|
443
|
+
name: Nauru
|
444
|
+
family: Austronesian
|
445
|
+
alpha3t: nau
|
446
|
+
nv:
|
447
|
+
name: Navajo
|
448
|
+
family: Dene-Yeniseian
|
449
|
+
alpha3t: nav
|
450
|
+
nb:
|
451
|
+
name: Norwegian Bokmål
|
452
|
+
family: Indo-European
|
453
|
+
alpha3t: nob
|
454
|
+
nd:
|
455
|
+
name: North Ndebele
|
456
|
+
family: Niger-Congo
|
457
|
+
alpha3t: nde
|
458
|
+
ne:
|
459
|
+
name: Nepali
|
460
|
+
family: Indo-European
|
461
|
+
alpha3t: nep
|
462
|
+
ng:
|
463
|
+
name: Ndonga
|
464
|
+
family: Niger-Congo
|
465
|
+
alpha3t: ndo
|
466
|
+
nn:
|
467
|
+
name: Norwegian Nynorsk
|
468
|
+
family: Indo-European
|
469
|
+
alpha3t: nno
|
470
|
+
x_no:
|
471
|
+
name: Norwegian
|
472
|
+
family: Indo-European
|
473
|
+
alpha3t: nor
|
474
|
+
ii:
|
475
|
+
name: Nuosu
|
476
|
+
family: Sino-Tibetan
|
477
|
+
alpha3t: iii
|
478
|
+
nr:
|
479
|
+
name: South Ndebele
|
480
|
+
family: Niger-Congo
|
481
|
+
alpha3t: nbl
|
482
|
+
oc:
|
483
|
+
name: Occitan
|
484
|
+
family: Indo-European
|
485
|
+
alpha3t: oci
|
486
|
+
oj:
|
487
|
+
name: Ojibwe
|
488
|
+
family: Algonquian
|
489
|
+
alpha3t: oji
|
490
|
+
cu:
|
491
|
+
name: Old Church Slavonic
|
492
|
+
family: Indo-European
|
493
|
+
alpha3t: chu
|
494
|
+
om:
|
495
|
+
name: Oromo
|
496
|
+
family: Afro-Asiatic
|
497
|
+
alpha3t: orm
|
498
|
+
or:
|
499
|
+
name: Oriya
|
500
|
+
family: Indo-European
|
501
|
+
alpha3t: ori
|
502
|
+
os:
|
503
|
+
name: Ossetian
|
504
|
+
family: Indo-European
|
505
|
+
alpha3t: oss
|
506
|
+
pa:
|
507
|
+
name: Panjabi
|
508
|
+
family: Indo-European
|
509
|
+
alpha3t: pan
|
510
|
+
pi:
|
511
|
+
name: Pāli
|
512
|
+
family: Indo-European
|
513
|
+
alpha3t: pli
|
514
|
+
fa:
|
515
|
+
name: Persian
|
516
|
+
family: Indo-European
|
517
|
+
alpha3t: fas
|
518
|
+
alpha3b: per
|
519
|
+
pl:
|
520
|
+
name: Polish
|
521
|
+
family: Indo-European
|
522
|
+
alpha3t: pol
|
523
|
+
ps:
|
524
|
+
name: Pashto
|
525
|
+
family: Indo-European
|
526
|
+
alpha3t: pus
|
527
|
+
pt:
|
528
|
+
name: Portuguese
|
529
|
+
family: Indo-European
|
530
|
+
alpha3t: por
|
531
|
+
qu:
|
532
|
+
name: Quechua
|
533
|
+
family: Quechuan
|
534
|
+
alpha3t: que
|
535
|
+
rm:
|
536
|
+
name: Romansh
|
537
|
+
family: Indo-European
|
538
|
+
alpha3t: roh
|
539
|
+
rn:
|
540
|
+
name: Kirundi
|
541
|
+
family: Niger-Congo
|
542
|
+
alpha3t: run
|
543
|
+
ro:
|
544
|
+
name: Romanian
|
545
|
+
family: Indo-European
|
546
|
+
alpha3t: ron
|
547
|
+
alpha3b: rum
|
548
|
+
ru:
|
549
|
+
name: Russian
|
550
|
+
family: Indo-European
|
551
|
+
alpha3t: rus
|
552
|
+
sa:
|
553
|
+
name: Sanskrit
|
554
|
+
family: Indo-European
|
555
|
+
alpha3t: san
|
556
|
+
sc:
|
557
|
+
name: Sardinian
|
558
|
+
family: Indo-European
|
559
|
+
alpha3t: srd
|
560
|
+
sd:
|
561
|
+
name: Sindhi
|
562
|
+
family: Indo-European
|
563
|
+
alpha3t: snd
|
564
|
+
se:
|
565
|
+
name: Northern Sami
|
566
|
+
family: Finno-Ugric
|
567
|
+
alpha3t: sme
|
568
|
+
sm:
|
569
|
+
name: Samoan
|
570
|
+
family: Austronesian
|
571
|
+
alpha3t: smo
|
572
|
+
sg:
|
573
|
+
name: Sango
|
574
|
+
family: Creole
|
575
|
+
alpha3t: sag
|
576
|
+
sr:
|
577
|
+
name: Serbian
|
578
|
+
family: Indo-European
|
579
|
+
alpha3t: srp
|
580
|
+
gd:
|
581
|
+
name: Scottish Gaelic
|
582
|
+
family: Indo-European
|
583
|
+
alpha3t: gla
|
584
|
+
sn:
|
585
|
+
name: Shona
|
586
|
+
family: Niger-Congo
|
587
|
+
alpha3t: sna
|
588
|
+
si:
|
589
|
+
name: Sinhala
|
590
|
+
family: Indo-European
|
591
|
+
alpha3t: sin
|
592
|
+
sk:
|
593
|
+
name: Slovak
|
594
|
+
family: Indo-European
|
595
|
+
alpha3t: slk
|
596
|
+
alpha3b: slo
|
597
|
+
sl:
|
598
|
+
name: Slovene
|
599
|
+
family: Indo-European
|
600
|
+
alpha3t: slv
|
601
|
+
so:
|
602
|
+
name: Somali
|
603
|
+
family: Afro-Asiatic
|
604
|
+
alpha3t: som
|
605
|
+
st:
|
606
|
+
name: Southern Sotho
|
607
|
+
family: Niger-Congo
|
608
|
+
alpha3t: sot
|
609
|
+
es:
|
610
|
+
name: Spanish
|
611
|
+
family: Indo-European
|
612
|
+
alpha3t: spa
|
613
|
+
su:
|
614
|
+
name: Sundanese
|
615
|
+
family: Indo-European
|
616
|
+
alpha3t: sun
|
617
|
+
sw:
|
618
|
+
name: Swahili
|
619
|
+
family: Niger-Congo
|
620
|
+
alpha3t: swa
|
621
|
+
ss:
|
622
|
+
name: Swati
|
623
|
+
family: Niger-Congo
|
624
|
+
alpha3t: ssw
|
625
|
+
sv:
|
626
|
+
name: Swedish
|
627
|
+
family: Indo-European
|
628
|
+
alpha3t: swe
|
629
|
+
ta:
|
630
|
+
name: Tamil
|
631
|
+
family: Dravidian
|
632
|
+
alpha3t: tam
|
633
|
+
te:
|
634
|
+
name: Telugu
|
635
|
+
family: Dravidian
|
636
|
+
alpha3t: tel
|
637
|
+
tg:
|
638
|
+
name: Tajik
|
639
|
+
family: Indo-European
|
640
|
+
alpha3t: tgk
|
641
|
+
th:
|
642
|
+
name: Thai
|
643
|
+
family: Tai-Kadai
|
644
|
+
alpha3t: tha
|
645
|
+
ti:
|
646
|
+
name: Tigrinya
|
647
|
+
family: Afro-Asiatic
|
648
|
+
alpha3t: tir
|
649
|
+
bo:
|
650
|
+
name: Tibetan Standard
|
651
|
+
family: Sino-Tibetan
|
652
|
+
alpha3t: bod
|
653
|
+
alpha3b: tib
|
654
|
+
tk:
|
655
|
+
name: Turkmen
|
656
|
+
family: Turkic
|
657
|
+
alpha3t: tuk
|
658
|
+
tl:
|
659
|
+
name: Tagalog
|
660
|
+
family: Austronesian
|
661
|
+
alpha3t: tgl
|
662
|
+
tn:
|
663
|
+
name: Tswana
|
664
|
+
family: Niger-Congo
|
665
|
+
alpha3t: tsn
|
666
|
+
tn:
|
667
|
+
name: Tonga
|
668
|
+
family: Austronesian
|
669
|
+
alpha3t: ton
|
670
|
+
tr:
|
671
|
+
name: Turkish
|
672
|
+
family: Turkic
|
673
|
+
alpha3t: tur
|
674
|
+
ts:
|
675
|
+
name: Tsonga
|
676
|
+
family: Niger-Congo
|
677
|
+
alpha3t: tso
|
678
|
+
tt:
|
679
|
+
name: Tatar
|
680
|
+
family: Turkic
|
681
|
+
alpha3t: tat
|
682
|
+
tw:
|
683
|
+
name: Twi
|
684
|
+
family: Niger-Congo
|
685
|
+
alpha3t: twi
|
686
|
+
ty:
|
687
|
+
name: Tahitian
|
688
|
+
family: Austronesian
|
689
|
+
alpha3t: tah
|
690
|
+
uh:
|
691
|
+
name: Uighur
|
692
|
+
family: Turkic
|
693
|
+
alpha3t: ukr
|
694
|
+
ur:
|
695
|
+
name: Urdu
|
696
|
+
family: Indo-European
|
697
|
+
alpha3t: urd
|
698
|
+
uz:
|
699
|
+
name: Uzbek
|
700
|
+
family: Indo-European
|
701
|
+
alpha3t: uzb
|
702
|
+
ve:
|
703
|
+
name: Venda
|
704
|
+
family: Niger-Congo
|
705
|
+
alpha3t: ven
|
706
|
+
vi:
|
707
|
+
name: Vietnamese
|
708
|
+
family: Austro-Asiatic
|
709
|
+
alpha3t: vie
|
710
|
+
vo:
|
711
|
+
name: Volapük
|
712
|
+
family: Constructed
|
713
|
+
alpha3t: vol
|
714
|
+
wa:
|
715
|
+
name: Walloon
|
716
|
+
family: Indo-European
|
717
|
+
alpha3t: wln
|
718
|
+
cy:
|
719
|
+
name: Welsh
|
720
|
+
family: Indo-European
|
721
|
+
alpha3t: cym
|
722
|
+
alpha3b: wel
|
723
|
+
wo:
|
724
|
+
name: Wolof
|
725
|
+
family: Indo-European
|
726
|
+
alpha3t: wol
|
727
|
+
fy:
|
728
|
+
name: Western Frisian
|
729
|
+
family: Indo-European
|
730
|
+
alpha3t: fry
|
731
|
+
xh:
|
732
|
+
name: Xhosa
|
733
|
+
family: Niger-Congo
|
734
|
+
alpha3t: xho
|
735
|
+
yi:
|
736
|
+
name: Yiddish
|
737
|
+
family: Indo-European
|
738
|
+
alpha3t: yid
|
739
|
+
yo:
|
740
|
+
name: Yoruba
|
741
|
+
family: Niger-Congo
|
742
|
+
alpha3t: yor
|
743
|
+
za:
|
744
|
+
name: Zhuang
|
745
|
+
family: Tai-Kadai
|
746
|
+
alpha3t: zha
|
747
|
+
zu:
|
748
|
+
name: Zulu
|
749
|
+
family: Niger-Congo
|
750
|
+
alpha3t: zul
|
data/lib/usa_state_translater.rb
CHANGED
@@ -8,9 +8,9 @@ module SunDawg
|
|
8
8
|
|
9
9
|
# O(N) translation from state name to 2-digit code
|
10
10
|
def self.translate_name_to_code(name)
|
11
|
-
USA_STATES.each_pair
|
11
|
+
USA_STATES.each_pair do |key, value|
|
12
12
|
return key if value["name"] == name
|
13
|
-
|
13
|
+
end
|
14
14
|
raise NoStateError.new("[#{name}] IS NOT VALID")
|
15
15
|
end
|
16
16
|
|
@@ -2,28 +2,28 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{sundawg_country_codes}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Christopher Sun"]
|
9
|
-
s.date = %q{2010-
|
10
|
-
s.description = %q{Manage ISO 3166 Country Names and Codes.}
|
9
|
+
s.date = %q{2010-08-27}
|
10
|
+
s.description = %q{Manage ISO 3166 Country Names and Codes, ISO 639 Languages, and ISO 4217 Currencies.}
|
11
11
|
s.email = %q{christopher.sun@gmail.com}
|
12
|
-
s.extra_rdoc_files = ["README", "lib/countries.yml", "lib/country_iso_translater.rb", "lib/usa_state_translater.rb", "lib/usa_states.yml"]
|
13
|
-
s.files = ["
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/countries.yml", "lib/country_iso_translater.rb", "lib/language_iso_translater.rb", "lib/languages.yml", "lib/usa_state_translater.rb", "lib/usa_states.yml"]
|
13
|
+
s.files = ["README.rdoc", "Rakefile", "lib/countries.yml", "lib/country_iso_translater.rb", "lib/language_iso_translater.rb", "lib/languages.yml", "lib/usa_state_translater.rb", "lib/usa_states.yml", "sundawg_country_codes.gemspec", "test/country_iso_translater_test.rb", "test/language_iso_translater_test.rb", "test/test_helper.rb", "test/usa_translater_test.rb", "Manifest"]
|
14
14
|
s.homepage = %q{http://github.com/SunDawg/country_codes}
|
15
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Sundawg_country_codes", "--main", "README"]
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Sundawg_country_codes", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubyforge_project = %q{sundawg_country_codes}
|
18
|
-
s.rubygems_version = %q{1.3.
|
19
|
-
s.summary = %q{Manage ISO 3166 Country Names and Codes.}
|
20
|
-
s.test_files = ["test/country_iso_translater_test.rb", "test/test_helper.rb", "test/usa_translater_test.rb"]
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
|
+
s.summary = %q{Manage ISO 3166 Country Names and Codes, ISO 639 Languages, and ISO 4217 Currencies.}
|
20
|
+
s.test_files = ["test/country_iso_translater_test.rb", "test/language_iso_translater_test.rb", "test/test_helper.rb", "test/usa_translater_test.rb"]
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
23
23
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
24
|
s.specification_version = 3
|
25
25
|
|
26
|
-
if Gem::Version.new(Gem::
|
26
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
27
27
|
else
|
28
28
|
end
|
29
29
|
else
|
@@ -61,7 +61,7 @@ class CountryIsoTranslaterTest < Test::Unit::TestCase
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def test_data_integrity
|
64
|
-
SunDawg::CountryIsoTranslater::COUNTRIES.each_pair
|
64
|
+
SunDawg::CountryIsoTranslater::COUNTRIES.each_pair do |k, v|
|
65
65
|
# check country codes
|
66
66
|
assert_not_nil v["alpha2"]
|
67
67
|
assert_not_nil v["alpha3"]
|
@@ -83,10 +83,10 @@ class CountryIsoTranslaterTest < Test::Unit::TestCase
|
|
83
83
|
end
|
84
84
|
|
85
85
|
# check to make sure currency_iso4217 is spelled correctly
|
86
|
-
v.each_pair
|
86
|
+
v.each_pair do |k2, v2|
|
87
87
|
assert_equal k2, "currency_iso4217" if (k2[0..1] == "c")
|
88
|
-
|
89
|
-
|
88
|
+
end
|
89
|
+
end
|
90
90
|
end
|
91
91
|
|
92
92
|
def test_error_on_invalid_currency
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# allows override of FILE
|
4
|
+
module SunDawg
|
5
|
+
module LanguageIsoTranslater
|
6
|
+
FILE = "lib/languages.yml"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'language_iso_translater'
|
11
|
+
|
12
|
+
class LangaugeIsoTranslaterTest < Test::Unit::TestCase
|
13
|
+
def test_english
|
14
|
+
h = client.get_iso_639_1_translation("en")
|
15
|
+
assert_equal "English", h['name']
|
16
|
+
assert_equal "eng", h['alpha3t']
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_norwegian
|
20
|
+
h = client.get_iso_639_1_translation("no")
|
21
|
+
assert_equal "Norwegian", h['name']
|
22
|
+
assert_equal "nor", h['alpha3t']
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_data_integrity
|
26
|
+
SunDawg::LanguageIsoTranslater::LANGUAGES.each_pair do |k, v|
|
27
|
+
assert_equal 2, k.to_s.size
|
28
|
+
assert v['name']
|
29
|
+
assert v['family']
|
30
|
+
assert v['alpha3t']
|
31
|
+
assert_equal 3, v['alpha3t'].size
|
32
|
+
assert ['Algonquian', 'Dene-Yeniseian', 'Japonic', 'Quechuan', 'Turkic', 'Northwest Caucasian', 'Nilo-Saharan', 'Language Isolate', 'Tai-Kadai', 'Sino-Tibetan', 'Aymaran', 'Constructed', 'Northeast Caucasian', 'Mongolic', 'Austro-Asiatic', 'South Caucasian', 'Tupi-Guarani', 'Creole', 'Finno-Ugric', 'Eskimo-Aleut', 'Turkic', 'Austronesian', 'Dravidian', 'Indo-European', 'Afro-Asiatic', 'Niger-Congo'].include?(v['family'])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
|
38
|
+
def client
|
39
|
+
SunDawg::LanguageIsoTranslater
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sundawg_country_codes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Christopher Sun
|
@@ -9,34 +15,39 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-
|
18
|
+
date: 2010-08-27 00:00:00 -04:00
|
13
19
|
default_executable:
|
14
20
|
dependencies: []
|
15
21
|
|
16
|
-
description: Manage ISO 3166 Country Names and Codes.
|
22
|
+
description: Manage ISO 3166 Country Names and Codes, ISO 639 Languages, and ISO 4217 Currencies.
|
17
23
|
email: christopher.sun@gmail.com
|
18
24
|
executables: []
|
19
25
|
|
20
26
|
extensions: []
|
21
27
|
|
22
28
|
extra_rdoc_files:
|
23
|
-
- README
|
29
|
+
- README.rdoc
|
24
30
|
- lib/countries.yml
|
25
31
|
- lib/country_iso_translater.rb
|
32
|
+
- lib/language_iso_translater.rb
|
33
|
+
- lib/languages.yml
|
26
34
|
- lib/usa_state_translater.rb
|
27
35
|
- lib/usa_states.yml
|
28
36
|
files:
|
29
|
-
-
|
30
|
-
- README
|
37
|
+
- README.rdoc
|
31
38
|
- Rakefile
|
32
39
|
- lib/countries.yml
|
33
40
|
- lib/country_iso_translater.rb
|
41
|
+
- lib/language_iso_translater.rb
|
42
|
+
- lib/languages.yml
|
34
43
|
- lib/usa_state_translater.rb
|
35
44
|
- lib/usa_states.yml
|
36
45
|
- sundawg_country_codes.gemspec
|
37
46
|
- test/country_iso_translater_test.rb
|
47
|
+
- test/language_iso_translater_test.rb
|
38
48
|
- test/test_helper.rb
|
39
49
|
- test/usa_translater_test.rb
|
50
|
+
- Manifest
|
40
51
|
has_rdoc: true
|
41
52
|
homepage: http://github.com/SunDawg/country_codes
|
42
53
|
licenses: []
|
@@ -48,29 +59,37 @@ rdoc_options:
|
|
48
59
|
- --title
|
49
60
|
- Sundawg_country_codes
|
50
61
|
- --main
|
51
|
-
- README
|
62
|
+
- README.rdoc
|
52
63
|
require_paths:
|
53
64
|
- lib
|
54
65
|
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
55
67
|
requirements:
|
56
68
|
- - ">="
|
57
69
|
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
58
73
|
version: "0"
|
59
|
-
version:
|
60
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
61
76
|
requirements:
|
62
77
|
- - ">="
|
63
78
|
- !ruby/object:Gem::Version
|
79
|
+
hash: 11
|
80
|
+
segments:
|
81
|
+
- 1
|
82
|
+
- 2
|
64
83
|
version: "1.2"
|
65
|
-
version:
|
66
84
|
requirements: []
|
67
85
|
|
68
86
|
rubyforge_project: sundawg_country_codes
|
69
|
-
rubygems_version: 1.3.
|
87
|
+
rubygems_version: 1.3.7
|
70
88
|
signing_key:
|
71
89
|
specification_version: 3
|
72
|
-
summary: Manage ISO 3166 Country Names and Codes.
|
90
|
+
summary: Manage ISO 3166 Country Names and Codes, ISO 639 Languages, and ISO 4217 Currencies.
|
73
91
|
test_files:
|
74
92
|
- test/country_iso_translater_test.rb
|
93
|
+
- test/language_iso_translater_test.rb
|
75
94
|
- test/test_helper.rb
|
76
95
|
- test/usa_translater_test.rb
|
data/README
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
ABOUT
|
2
|
-
-----
|
3
|
-
This project is a Ruby gem to manage ISO 3166 country names and their corresponding alpha-2 and alpha-3 codes.
|
4
|
-
|
5
|
-
Reference information can be found:
|
6
|
-
|
7
|
-
ISO3166 Country Codes
|
8
|
-
http://en.wikipedia.org/wiki/ISO_3166-1
|
9
|
-
|
10
|
-
ISO4217 Currency Information
|
11
|
-
http://www.xe.com/iso4217.php
|
12
|
-
http://www.xe.com/symbols.php
|
13
|
-
|
14
|
-
TEST
|
15
|
-
----
|
16
|
-
Tests can be executed by running:
|
17
|
-
|
18
|
-
rake test
|
19
|
-
|
20
|
-
SAMPLE USAGE
|
21
|
-
------------
|
22
|
-
To translate from a country's name to their ISO Alpha-2 code:
|
23
|
-
|
24
|
-
SunDawg::CountryIsoTranslater.translate_iso3166_name_to_alpha2("United States")
|
25
|
-
|
26
|
-
To translate from a country's name to their ISO Alpha-3 code:
|
27
|
-
|
28
|
-
SunDawg::CountryIsoTranslater.translate_iso3166_name_to_alpha3("Egypt")
|
29
|
-
|
30
|
-
To translate from a country's ISO Alpha-2 code to country name:
|
31
|
-
|
32
|
-
SunDawg::CountryIsoTranslater.translate_iso3166_alpha2_to_name("US")
|
33
|
-
|
34
|
-
To translate form a country's ISO Alpha-3 code to country name:
|
35
|
-
|
36
|
-
SunDawg::CountryIsoTranslater.translate_iso3166_alpha3_to_name("ESP")
|
37
|
-
|
38
|
-
To obtain currency information for a country:
|
39
|
-
|
40
|
-
currency = SunDawg::CountryIsoTranslater.get_iso4217_currency_by_iso3166_alpha2("US")
|
41
|
-
assert_equal currency["code"], "USD"
|
42
|
-
assert_equal currency["symbol"], "$"
|
43
|
-
assert_equal currency["name"], "Dollars"
|
44
|
-
assert_equal currency["unicode_hex"], 36
|
45
|
-
|
46
|
-
NOTE:
|
47
|
-
|
48
|
-
Not all countries have currency information and not all currency information contains both the symbol. Some currency information contain a second currency under the curreny["alt_currency"] which will then contain the same hash values for a currency.
|
49
|
-
|
50
|
-
Furthermore, while the hex value for representing the unicode symbol is stored in the .yml file, the import into Ruby is converting it into decimal. You can convert back to hex as so:
|
51
|
-
|
52
|
-
assert_equal currency["unicode_hex"].to_s(16), "24"
|
53
|
-
|
54
|
-
The unicode value, either in base 10 or base 16 will allow you to render the symbol properly in HTML:
|
55
|
-
|
56
|
-
$ or $
|
57
|
-
|
58
|
-
More information:
|
59
|
-
|
60
|
-
http://www.fileformat.info/info/unicode/char/0024/index.htm
|
61
|
-
|
62
|
-
To build the unicode HTML for a symbol:
|
63
|
-
|
64
|
-
currency = SunDawg::CountryIsoTranslater.get_iso4217_currency_by_iso3166_alpha2("UZ")
|
65
|
-
assert_equal SunDawg::CountryIsoTranslater.build_html_unicode(currency["unicode_hex"]), "лв"
|
66
|
-
|
67
|
-
To translate to and from USA state name and the 2-digit code:
|
68
|
-
|
69
|
-
SunDawg::USAStateTranslater.translate_name_to_code('New York')
|
70
|
-
SunDawg::USAStateTranslater.translate_code_to_name('NY')
|
71
|
-
|
72
|
-
DATA
|
73
|
-
----
|
74
|
-
All country code and names are stored in a countries.yml file that can be changed as you need. The latest codes and country names are derived from:
|
75
|
-
|
76
|
-
http://en.wikipedia.org/wiki/ISO_3166-1
|
77
|
-
|
78
|
-
GEM INSTALL
|
79
|
-
-----------
|
80
|
-
This gem is hosted gemcutter.org. To install the gem, you should install gemcutter as so:
|
81
|
-
|
82
|
-
sudo gem install gemcutter
|
83
|
-
gem tumble
|
84
|
-
|
85
|
-
This will add gemcutter to your gem repository for downloading the country_codes gem.
|
86
|
-
|
87
|
-
RAILS INSTALL
|
88
|
-
-------------
|
89
|
-
To include this gem in your Rails project, add the following to your config/environment.rb:
|
90
|
-
|
91
|
-
config.gem 'sundawg_country_codes', :lib => 'country_iso_translater'
|
92
|
-
|
93
|
-
VERSION HISTORY
|
94
|
-
---------------
|
95
|
-
v0.0.3 - Added USA State translater and cleaned up unit tests.
|
96
|
-
v0.0.2b - Completed all currency information, unicode HTML utility, and bug fixes. Gem version re-published as 0.0.2.
|
97
|
-
v0.0.2 - Added ISO 4217 currency information.
|
98
|
-
v0.0.1 - Allows basic ISO 3166 translation.
|