Core/src/main/java/org/openestate/io/core/LocaleUtils.java
public static String getCountryISO2(String country) {
        country = StringUtils.trimToNull(country);
        if (country == null)
            return null;
        if (country.length() == 2)
            return country;

        String[] iso2Codes = Locale.getISOCountries();
        if (country.length() == 3) {
            String iso2Code = LocaleUtils.getCountryISO2FromISO3(country);
            if (iso2Code != null) return iso2Code;
        }

        for (String iso2Code : iso2Codes) {
            Locale countryLocale = new Locale(iso2Code, iso2Code);
            for (Locale translationLocale : LocaleUtils.availableLocaleList()) {
                String name = StringUtils.trimToNull(countryLocale.getDisplayCountry(translationLocale));
                if (name != null && name.equalsIgnoreCase(country)) return iso2Code;
            }
        }
        return null;
    }
public static String getCountryISO2(String country) {
        country = StringUtils.trimToNull(country);
        if (country == null)
            return null;
        if (country.length() == 2)
            return country;

        String[] iso2Codes = Locale.getISOCountries();
        if (country.length() == 3) {
            String iso2Code = LocaleUtils.getCountryISO2FromISO3(country);
            if (iso2Code != null) return iso2Code;
        }

        for (String iso2Code : iso2Codes) {
            Locale countryLocale = new Locale(iso2Code, iso2Code);
            for (Locale translationLocale : LocaleUtils.availableLocaleList()) {
                String name = StringUtils.trimToNull(countryLocale.getDisplayCountry(translationLocale));
                if (name != null && name.equalsIgnoreCase(country)) return iso2Code;
            }
        }
        return null;
    }
public static String getCountryISO2 ( String country ) { country = StringUtils . trimToNull ( country ) ; if ( country == null ) return null ; if ( country . length ( ) == 2 ) return country ; String [ ] iso2Codes = Locale . getISOCountries ( ) ; if ( country . length ( ) == 3 ) { String iso2Code = LocaleUtils . getCountryISO2FromISO3 ( country ) ; if ( iso2Code != null ) return iso2Code ; } for ( String iso2Code : iso2Codes ) { Locale countryLocale = new Locale ( iso2Code , iso2Code ) ; for ( Locale translationLocale : LocaleUtils . availableLocaleList ( ) ) { String name = StringUtils . trimToNull ( countryLocale . getDisplayCountry ( translationLocale ) ) ; if ( name != null && name . equalsIgnoreCase ( country ) ) return iso2Code ; } } return null ; }
Return an ISO-2 country code from a country name.

@param country country name
@return ISO-2 country code or null, if no code was found
Return an ISO - 2 country code from a country name .