Example usage for java.util Locale getDisplayCountry

List of usage examples for java.util Locale getDisplayCountry

Introduction

In this page you can find the example usage for java.util Locale getDisplayCountry.

Prototype

public final String getDisplayCountry() 

Source Link

Document

Returns a name for the locale's country that is appropriate for display to the user.

Usage

From source file:Main.java

public static ArrayList<String> getCountriesArray1() {
    Locale[] locales = Locale.getAvailableLocales();
    ArrayList<String> countries = new ArrayList<String>();
    for (Locale locale : locales) {
        String country = locale.getDisplayCountry();
        Currency currency = Currency.getInstance(locale);
        if (country.trim().length() > 0 && !countries.contains(country) && !country.trim().equals("World")) {
            countries.add(country + " (" + currency + ")");
        }// www  .  j av  a 2s .co  m
    }
    Collections.sort(countries);
    setCountriesISOMap();
    return countries;
}

From source file:Main.java

public static void setCountriesISOMap() {
    String[] isoCountryCodes = Locale.getISOCountries();
    for (int i = 0; i < isoCountryCodes.length; i++) {
        Locale locale = new Locale("", isoCountryCodes[i]);
        countriesISOMap.put(locale.getDisplayCountry(), isoCountryCodes[i]);
    }//from   www . ja  va  2  s  .c om
}

From source file:Main.java

public static String getSpinnertextCountry(String countryCode) {

    Locale locale = new Locale("", countryCode);
    try {/*  www .  j av  a  2  s  .  c  o  m*/
        Currency currency = Currency.getInstance(locale);
        return locale.getDisplayCountry() + " (" + currency.getCurrencyCode() + ")";
    } catch (Exception e) {

    }
    return "";
}

From source file:io.leishvl.core.util.LocaleUtils.java

/**
 * Obtains the locale that best-matches with the specified string.
 * @param str input string.//w  ww  .j av a 2  s  .c  om
 * @return the locale that best-matches with the specified string, or {@code null}.
 */
public static @Nullable Locale getLocale(final @Nullable String str) {
    Locale locale = null;
    if (isNotBlank(str)) {
        final ImmutableList<Locale> locales = availableLocaleList();
        for (int i = 0; i < locales.size() && locale == null; i++) {
            final Locale item = locales.get(i);
            if (containsIgnoreCase(str, item.getDisplayCountry())) {
                locale = item;
            }
        }
    }
    return locale;
}

From source file:eu.eubrazilcc.lvl.core.util.LocaleUtils.java

/**
 * Obtains the locale that best-matches with the specified string.
 * @param str input string./* ww  w. j a v  a 2s .  c  o  m*/
 * @return the locale that best-matches with the specified string, or {@code null}.
 */
public static @Nullable Locale getLocale(final @Nullable String str) {
    Locale locale = null;
    if (isNotBlank(str)) {
        final ImmutableList<Locale> locales = availableLocaleList();
        for (int i = 0; i < locales.size() && locale == null; i++) {
            final Locale item = locales.get(i);
            if (StringUtils.containsIgnoreCase(str, item.getDisplayCountry())) {
                locale = item;
            }
        }
    }
    return locale;
}

From source file:Main.java

public static ArrayList<String> getCountriesArray() {
    String[] locales = Locale.getISOCountries();
    ArrayList<String> countries = new ArrayList<String>();
    for (String countryCode : locales) {

        Locale locale = new Locale("", countryCode);
        try {//from  w w  w. j a va  2s.co m
            Currency currency = Currency.getInstance(locale);
            countries.add(locale.getDisplayCountry() + " (" + currency.getCurrencyCode() + ")");
        } catch (Exception e) {

        }
    }
    Collections.sort(countries);
    return countries;
}

From source file:ListOfCitys.CityList.java

private static String getCountryName(String zone) throws IOException {
    String[] arry = zone.split(";"); //EU;DE
    zone = arry[1];/*  w ww  .ja  va  2  s . co  m*/
    String[] locales = Locale.getISOCountries();
    String countryName = "";
    JSONArray countryWithCities = new JSONArray();
    Map<String, List<String>> countryWithCityNames = new HashMap<>();
    for (String countryCode : locales) {
        Locale obj = new Locale("", countryCode);
        System.out
                .println("Country Code = " + obj.getCountry() + ", Country Name = " + obj.getDisplayCountry());
        countryWithCities.add(getCityNameForCountry(obj.getCountry(), countryCode));
        if (obj.getCountry().equalsIgnoreCase(zone)) {
            countryName = obj.getDisplayCountry();
            break;
        }
    }
    System.out.println("-----json array --- " + countryWithCities.toJSONString());
    try (FileWriter file = new FileWriter("test.json")) {
        file.write(countryWithCities.toJSONString());
    }
    return countryName;
}

From source file:Main.java

public static void printLocaleDetails(Locale locale) {
    String languageCode = locale.getLanguage();
    String languageName = locale.getDisplayLanguage();
    String countryCode = locale.getCountry();
    String countryName = locale.getDisplayCountry();
    // Print the locale info
    System.out.println("Language: " + languageName + "(" + languageCode + "); " + "Country: " + countryName
            + "(" + countryCode + ")");
}

From source file:Main.java

public static String getCountryCode(String spinnerText) {
    String[] locales = Locale.getISOCountries();
    ArrayList<String> countries = new ArrayList<>();
    for (String countryCode : locales) {

        Locale locale = new Locale("", countryCode);
        try {/*from  w  ww .j av  a 2 s . c o  m*/
            Currency currency = Currency.getInstance(locale);
            String proposedSpinnerText = locale.getDisplayCountry() + " (" + currency.getCurrencyCode() + ")";

            if (proposedSpinnerText.equals(spinnerText)) {
                return countryCode;
            }
        } catch (Exception e) {

        }
    }
    return "";
}

From source file:net.rrm.ehour.ui.admin.config.MainConfigBackingBean.java

public static List<Locale> getAvailableLocales() {
    List<Locale> locales = new ArrayList<>();

    for (Locale locale : Locale.getAvailableLocales()) {
        if (!StringUtils.isBlank(locale.getDisplayCountry())) {
            locales.add(locale);/*from   w w w.  j  a va  2 s .c om*/
        }
    }

    Collections.sort(locales, new LocaleComparator(LocaleComparator.CompareType.COUNTRY));

    return locales;
}