Skip to content
/ jcountry Public
forked from castmart/jcountry

A wrapper library for country iso codes (inspired by pycountry)

License

Notifications You must be signed in to change notification settings

Jimdo/jcountry

 
 

Repository files navigation

JCountry

This project tries to replicate the same functionality as pycountry by wrapping iso files and provide a programatic interface.

This will help having a quick source for translations of country names, and the extra information provided by:

  • ISO 3166-1 (Countries)
  • ISO 639-2 (Languages)

For the status of the translations, please check the iso codes repository (which is the original source of the iso files and translations).

Dependency

// Gradle Kotlin
implementation("com.jimdo:jcountry:0.1.0")

How to use it?

    JCountry jcountry = new JCountry();
    CountryDB countryDB = jcountry.getCountriesDB();
    // Get the countries DB hash maps <String, Country>
    var dbByAlpha2 = countryDB.getCountriesMapByAlpha2();
    var dbByAlpha3 = countryDB.getCountriesMapByAlpha3();
    var dbByName = countryDB.getCountriesMapByName();
    
    // Get Translations by language based locale 
    Optional<ResourceBundle> bundle = countryDB.getCountriesTranslations(Locale.GERMAN);
    
    // MX -> Mexiko
    var translatedCountryName = bundle.get().getString(dbByAlpha2.get("MX").getName());

    // Languages DB
    LanguageDB languageDB = new LanguageDBImpl(true);
    var dbByAlpha2 = languageDB.getLanguagesMapByAlpha2();

    // Get Translations by language based locale 
    Optional<ResourceBundle> bundle = languageDB.getLanguagesTranslations(Locale.GERMAN);
    
    // Spanisch (Kastilisch)
    var translatedCountryName = bundle.get().getString(dbByAlpha2.get("es").getName());

About

A wrapper library for country iso codes (inspired by pycountry)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 77.7%
  • Kotlin 15.7%
  • Makefile 5.1%
  • Shell 1.5%