Elixir Module containing data about Countries, states and their regions as per iso standard.
This package is a port of carmen ruby gem
Warning
Alpha Quality(Work in Progress). Reads the files for every function call.
TODO
- Improve performance by utilizing the OTP.
- Add proper localization support.
- Better Documentation [Module and Function docs]
- Allow countries or regions to be extended in App
- Publish to Hex.
- Add Tests
-
Add worldly to your list of dependencies in
mix.exs.def deps do [ {:yamerl, github: "yakaz/yamerl"}, {:worldly, "~> 0.1.2"} ] end -
Ensure worldly and yamerl is started before your application:
def application do [applications: [:yamerl, :worldly]] end -
Add worldly config data path in config/config.exs
config :worldly, :data_path, Path.join(Mix.Project.build_path, "lib/worldly/priv/data") -
You can also checkout a demo mix project showing use of worldly and its setup. Check README and commit-history (4 commits only :) )
Disclaimer: - Locale need to be added for all corresponding entries in countries or regions to provide name and other relevant information. It might crash if corresponding locale mapping missing.
- To get the list of countries use
Worldly.Country.all - You can get country by name using
Worldly.Country.with_name name_in_locale - You can get country by code using
Worldly.Country.with_code alpha_2_codeorWorldly.Country.with_code alpha_3_code - To get the regions for a country, use
Worldly.Region.regions_for country_or_region, where country_or_region can be a country structWorldy.Countryor region structWorldy.Region - You can also whether sub-regions exist for country or a region, use
Worldly.Region.regions_for country_or_region, where country_or_region can be a country structWorldy.Countryor region structWorldy.Region