/** * Get the country name from the country code. If the code is null or empty * then it is considered to be DEFAULT_COUNTRY_CODE (that is, US). * Otherwise, it will generate a log message and return unknown. If a locale * is used for the iso3166Code, it will use the part before the '_'. Thus, * this code does not support dialects, except as found in the iso3166. * * @param iso3166Code the country code * @return the name of the country */ public static String getCountry(String iso3166Code) { String lookup = iso3166Code; if (lookup == null || lookup.length() == 0) { return getCountry(DEFAULT_COUNTRY_CODE); } if (lookup.indexOf('_') != -1) { String[] locale = StringUtil.split(lookup, '_'); return getCountry(locale[1]); } try { return getLocalisedCountries().getString(lookup); } catch (MissingResourceException e) { return getCountry(UNKNOWN_COUNTRY_CODE); } }
/** * Determine whether the country code is valid. The code is valid if it is * null or empty. The code is valid if it is in iso3166.properties. If a * locale is used for the iso3166Code, it will use the part after the '_'. * Thus, this code does not support dialects. * * @param iso3166Code the country code * @return true if the country is valid. */ public static boolean isValidCountry(String iso3166Code) { String lookup = iso3166Code; if (lookup == null || lookup.length() == 0) { return true; } if (lookup.indexOf('_') != -1) { String[] locale = StringUtil.split(lookup, '_'); return isValidCountry(locale[1]); } if (lookup.length() > 2) { return false; } try { getLocalisedCountries().getString(lookup); return true; } catch (MissingResourceException e) { return false; } }
public String toString(String translationCode) { StringBuilder currentTranslation = new StringBuilder(Languages.getName(translationCode)); if (translationCode.indexOf('_') != -1) { String[] locale = StringUtil.split(translationCode, '_'); currentTranslation.append(", "); currentTranslation.append(Countries.getCountry(locale[1])); } return currentTranslation.toString(); }