Last active
August 14, 2018 22:36
-
-
Save spro/a8f0b59d5f6b4951320563cc392d3ec5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'countries' | |
require 'json' | |
ISO3166.configure do |config| | |
config.locales = [:en, :cs, :de, :es, :fr, :ja, :nl, :sk] | |
end | |
# { | |
# AF: { | |
# name: { | |
# en: "Afghanistan" | |
# fr: "Afghanistan" | |
# } | |
# subdivisions: { | |
# BAL: { | |
# name: { | |
# en: "Balkh" | |
# fr: "Balkh" | |
# } | |
# } | |
# } | |
# } | |
# } | |
# | |
country_codes = ISO3166::Data.codes | |
countries_data = Hash[country_codes.collect { |country_code| | |
country = ISO3166::Country.new(country_code) | |
subdivision_codes = country.subdivisions.keys | |
subdivisions_data = Hash[subdivision_codes.collect { |subdivision_code| | |
subdivision_data = { | |
:name => country.subdivisions[subdivision_code].translations | |
} | |
[subdivision_code, subdivision_data] | |
}] | |
country_data = { | |
:name => country.translations, | |
:subdivisions => subdivisions_data | |
} | |
[country_code, country_data] | |
}] | |
print JSON.generate countries_data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment