Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 1.59 KB

README.md

File metadata and controls

41 lines (31 loc) · 1.59 KB

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());