Skip to content

Instantly share code, notes, and snippets.

@spro
Last active August 14, 2018 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spro/a8f0b59d5f6b4951320563cc392d3ec5 to your computer and use it in GitHub Desktop.
Save spro/a8f0b59d5f6b4951320563cc392d3ec5 to your computer and use it in GitHub Desktop.
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