hbb20 / CountryCodePickerProject

Country Code Picker (CCP) is an android library which provides an easy way to search and select country or international phone code. Also supports Android EditText phone mask and international phone validation.
Apache License 2.0
1.52k stars 505 forks source link

Using Java's own Locale data for region names #302

Open Huulivoide opened 5 years ago

Huulivoide commented 5 years ago

Instead of having to duplicate and manually translate the region names and data with the raw xml files, Java's build-in Locale data could probably be used.

Current we are using a following trick to generate a list of localized country names for the user to select from:

// Code in Kotlin

Locale
  .getISOCountries() // Fetch list of ISO 3166 country codes
  .map { // Create a new Locale in users default language, but set country to X
    it to Locale("", it).displayCountry // then extract the localized name of the country.
  } 
  .toMap() // Turn into Map with ISO 3166 key and Localised country name as value
hbb20 commented 5 years ago

@Huulivoide, thank you so much for this. We were looking for something like this. We will check the feasibility of this and incorporate this idea.