2 releases

0.1.0 Dec 25, 2024
0.1.0-alpha1 Dec 18, 2024

#31 in Internationalization (i18n)

Download history 94/week @ 2024-12-12 147/week @ 2024-12-19 77/week @ 2024-12-26 51/week @ 2025-01-02

369 downloads per month

MIT license

2MB
53K SLoC

GeoDB

Comprehensive geographical information

Crates.io MIT licensed Documentation Build Status Build Status Build Status

Features

  • ISO 3166-1 alpha2 & alpha3 country codes
  • ISO 3166-2 subdivision codes
  • ISO 4217 currency codes
  • BCP 47 language tags
  • Human-validated datasets
  • Comprehensive information

Example

use geodb::*;

fn main() {
    assert_eq!(Country::from_code("US"), Some(Country::US));
    assert_eq!(Country::from_code("US"), Country::from_code("USA"));
    assert_eq!(Country::US.continent(), Continent::NA);
    assert_eq!(Country::US.language(), &[Language::EN_US]);
    assert_eq!(Country::US.currency(), Currency::USD);
    assert_eq!(Country::US.dial(), "+1");
    assert_eq!(Country::US.tld(), ".us");
    assert_eq!(Country::US.name(), "United States");
    assert_eq!(Country::US.capital(), "Washington, D.C.");

    assert_eq!(Country::from_code("CN"), Some(Country::CN));
    assert_eq!(Country::from_code("CN"), Country::from_code("CHN"));
    assert_eq!(Country::CN.continent(), Continent::AS);
    assert_eq!(Country::CN.language(), &[Language::ZH_CN]);
    assert_eq!(Country::CN.currency(), Currency::CNY);
    assert_eq!(Country::CN.dial(), "+86");
    assert_eq!(Country::CN.tld(), ".cn");
    assert_eq!(Country::CN.name(), "China");
    assert_eq!(Country::CN.capital(), "Beijing");

    assert_eq!(Subdivision::from_code("JP-13"), Some(Subdivision::JP_13));
    assert_eq!(Subdivision::JP_13.country(), Country::JP);
    assert_eq!(Subdivision::JP_13.category(), "Prefecture");
    assert_eq!(Subdivision::JP_13.name(), "Tokyo");
    assert_eq!(Subdivision::JP_13.native(), "東京");

    assert_eq!(Currency::from_code("GBP"), Some(Currency::GBP));
    assert_eq!(Currency::GBP.symbol(), "£");
    assert_eq!(Currency::GBP.name(), "British Pound");
    assert_eq!(Currency::GBP.plural(), "British Pounds");

    assert_eq!(Language::from_code("zh-HK"), Some(Language::ZH_HK));
    assert_eq!(Language::ZH_HK.name(), "Traditional Chinese (Hong Kong)");
    assert_eq!(Language::ZH_HK.native(), "繁體中文 (香港)");
}

Documentation

The documentation is available here.

Reference

License

This software is released under the MIT License.

Dependencies

~0.4–1.6MB
~32K SLoC