List of usage examples for org.apache.commons.lang3 LocaleUtils languagesByCountry
public static List<Locale> languagesByCountry(final String countryCode)
Obtains the list of languages supported for a given country.
This method takes a country code and searches to find the languages available for that country.
From source file:com.aestheticsw.jobkeywords.service.termextractor.support.SearchUtils.java
public static Locale lookupLocaleByCountry(String country) { List<Locale> localeList = LocaleUtils.languagesByCountry(country); if (localeList == null || localeList.size() == 0) { throw new IllegalArgumentException("Invalid country code: " + country); }//from w w w . ja v a2s. c o m Locale locale = localeList.get(0); // if English isn't the language of the first Locale, then try to find English. if (!locale.getLanguage().equals("en")) { for (Locale option : localeList) { if (option.getLanguage().equals("en")) { return option; } } } return locale; }
From source file:dhbw.clippinggorilla.userinterface.windows.NewSourceWindow.java
public static Map<String, Locale> getCountries() { List<String> countries = Arrays.asList(Locale.getISOCountries()); HashMap<String, Locale> mapCountries = new HashMap<>(); countries.parallelStream().forEach((country) -> { List<Locale> locales = LocaleUtils.languagesByCountry(country); if (!locales.isEmpty()) { mapCountries.put(country, new Locale(locales.get(0).getLanguage(), country)); }//from w w w.j a va2 s . c om }); return mapCountries; }