List of usage examples for java.util Locale getVariant
public String getVariant()
From source file:com.clark.func.Functions.java
/** * <p>/*w w w. j av a 2s .c om*/ * Obtains the list of locales to search through when performing a locale * search. * </p> * * <pre> * localeLookupList(Locale("fr", "CA", "xxx"), Locale("en")) * = [Locale("fr","CA","xxx"), Locale("fr","CA"), Locale("fr"), Locale("en"] * </pre> * * <p> * The result list begins with the most specific locale, then the next more * general and so on, finishing with the default locale. The list will never * contain the same locale twice. * </p> * * @param locale * the locale to start from, null returns empty list * @param defaultLocale * the default locale to use if no other is found * @return the unmodifiable list of Locale objects, 0 being locale, never * null */ public static List<Locale> localeLookupList(Locale locale, Locale defaultLocale) { List<Locale> list = new ArrayList<Locale>(4); if (locale != null) { list.add(locale); if (locale.getVariant().length() > 0) { list.add(new Locale(locale.getLanguage(), locale.getCountry())); } if (locale.getCountry().length() > 0) { list.add(new Locale(locale.getLanguage(), "")); } if (list.contains(defaultLocale) == false) { list.add(defaultLocale); } } return Collections.unmodifiableList(list); }
From source file:com.clark.func.Functions.java
/** * <p>/*from w w w. ja va 2s . c o m*/ * Obtains the list of countries supported for a given language. * </p> * * <p> * This method takes a language code and searches to find the countries * available for that language. Variant locales are removed. * </p> * * @param languageCode * the 2 letter language code, null returns empty * @return an unmodifiable List of Locale objects, never null */ public static List<Locale> countriesByLanguage(String languageCode) { List<Locale> countries = cCountriesByLanguage.get(languageCode); // syncd if (countries == null) { if (languageCode != null) { countries = new ArrayList<Locale>(); List<Locale> locales = availableLocaleList(); for (int i = 0; i < locales.size(); i++) { Locale locale = locales.get(i); if (languageCode.equals(locale.getLanguage()) && locale.getCountry().length() != 0 && locale.getVariant().length() == 0) { countries.add(locale); } } countries = Collections.unmodifiableList(countries); } else { countries = Collections.emptyList(); } cCountriesByLanguage.put(languageCode, countries); // syncd } return countries; }