List of usage examples for java.util Locale getCountry
public String getCountry()
From source file:com.haulmont.cuba.core.entity.LocaleHelper.java
public static String getEnumLocalizedValue(String enumValue, String localeBundle) { if (enumValue == null) { return null; }//from w ww . j a v a2 s . c o m if (localeBundle == null) { return enumValue; } Map<String, String> map = getLocalizedValuesMap(localeBundle); Locale locale = AppBeans.get(UserSessionSource.class).getLocale(); String key = locale.getLanguage(); if (StringUtils.isNotEmpty(locale.getCountry())) { key += "_" + locale.getCountry(); } String result = map.getOrDefault(key + "/" + enumValue, ""); return Objects.equals(result, "") ? enumValue : result; }
From source file:LocaleMap.java
public static String getString(Locale locale) { boolean hasLanguage = !locale.getLanguage().equals(""); boolean hasCountry = !locale.getCountry().equals(""); boolean hasVariant = !locale.getVariant().equals(""); if (hasLanguage && hasCountry && hasVariant) return locale.getLanguage() + '-' + locale.getCountry() + '-' + locale.getVariant(); else if (hasLanguage && hasCountry) return locale.getLanguage() + '-' + locale.getCountry(); else if (hasLanguage) return locale.getLanguage(); else/*from w w w. j a v a 2s .co m*/ return ""; }
From source file:com.omnigon.aem.common.utils.LocaleUtils.java
public static String getLanguageCountryCode(Locale locale) { if (locale != null) { StringBuilder b = new StringBuilder(); if (StringUtils.isNotBlank(locale.getLanguage())) { b.append(locale.getLanguage().toLowerCase()); }//w w w .j a va 2 s .co m if (StringUtils.isNotBlank(locale.getCountry())) { b.append("_"); b.append(locale.getCountry().toLowerCase()); } return b.toString(); } else { return StringUtils.EMPTY; } }
From source file:net.rrm.ehour.ui.admin.config.MainConfigBackingBean.java
public static List<Locale> getAvailableCurrencies() { List<Locale> locales = getAvailableLocales(); SortedSet<Locale> currencyLocales = new TreeSet<>(new Comparator<Locale>() { public int compare(Locale o1, Locale o2) { Currency curr1 = Currency.getInstance(o1); Currency curr2 = Currency.getInstance(o2); return (o1.getDisplayCountry() + ": " + curr1.getSymbol(o1)) .compareTo(o2.getDisplayCountry() + ": " + curr2.getSymbol(o2)); }// ww w .ja va 2s .co m }); for (Locale locale : locales) { if (!StringUtils.isBlank(locale.getCountry())) { currencyLocales.add(locale); } } return new ArrayList<>(currencyLocales); }
From source file:com.gudong.appkit.utils.Utils.java
private static String getLanguageEnv() { Locale l = Locale.getDefault(); String language = l.getLanguage(); String country = l.getCountry().toLowerCase(); if ("zh".equals(language)) { if ("cn".equals(country)) { language = "zh-CN"; } else if ("tw".equals(country)) { language = "zh-TW"; }/*from w w w .ja v a 2 s .c o m*/ } else if ("pt".equals(language)) { if ("br".equals(country)) { language = "pt-BR"; } else if ("pt".equals(country)) { language = "pt-PT"; } } return language; }
From source file:Main.java
/** * <p>Obtains the list of locales to search through when performing * a locale search.</p>/*from w w w .j ava 2s.co m*/ * * <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, not 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)) { list.add(defaultLocale); } } return Collections.unmodifiableList(list); }
From source file:com.haulmont.cuba.core.entity.LocaleHelper.java
public static String getLocalizedEnumeration(String enumerationValues, String localeBundle) { String result = null;/*from w w w. j a v a 2s . c o m*/ if (StringUtils.isNotEmpty(localeBundle)) { Properties localeProperties = loadProperties(localeBundle); if (localeProperties != null) { Locale locale = AppBeans.get(UserSessionSource.class).getLocale(); String key = locale.getLanguage(); if (StringUtils.isNotEmpty(locale.getCountry())) { key += "_" + locale.getCountry(); } List<String> enumValues = new ArrayList<>(); String[] enumerationValuesArray = enumerationValues.split(","); Map<String, String> localizedValuesMap = LocaleHelper.getLocalizedValuesMap(localeBundle); for (String value : enumerationValuesArray) { String resultValue = localizedValuesMap.getOrDefault(key + "/" + value, value); enumValues.add(resultValue); } result = Joiner.on(",").join(enumValues); } } return result; }
From source file:com.monarchapis.driver.exception.ConfigurationBundleApiErrorFactory.java
/** * Returns the array of strings based on the request locales. * //from ww w . j a v a 2s .c o m * @param request * The API request * @return the array of variant strings */ private static String[] getLocaleArray(ApiRequest request) { Enumeration<Locale> locales = request.getLocales(); ArrayList<String> localeList = new ArrayList<String>(5); while (locales.hasMoreElements()) { Locale locale = locales.nextElement(); locale = new Locale(locale.getLanguage(), locale.getCountry()); String lang = locale.getLanguage(); if (StringUtils.isNotBlank(lang) && !"null".equals(lang)) { if (StringUtils.isNotBlank(locale.getCountry())) { localeList.add(locale.getLanguage() + '-' + locale.getCountry()); } localeList.add(locale.getLanguage()); } } return localeList.toArray(new String[localeList.size()]); }
From source file:org.openmrs.util.LocaleUtility.java
/** * Compatible is a looser matching than that provided by Locale.equals(). Two locales are * considered equal if they are equal, or if either does not have a country specified and the * languages match.//from w ww . j ava2 s .c o m * * @param lhs left hand side Locale * @param rhs right hand side Locale * @return true if the two locales are compatible, false otherwise * @should confirm different language missing country as compatible * @should confirm same language missing country as compatible * @should not confirm different country as compatible * @should confirm matching country as compatible * @should not confirm different language as compatible * @should confirm matching language as compatible */ public static boolean areCompatible(Locale lhs, Locale rhs) { if (lhs.equals(rhs)) { return true; } else if ((("".equals(lhs.getCountry())) || ("".equals(rhs.getCountry()))) && lhs.getLanguage().equals(rhs.getLanguage())) { // no country specified, so language match is good enough return true; } return false; }
From source file:fr.gouv.culture.thesaurus.util.LangUtils.java
public static String localeString(Locale locale) { List<String> components = new LinkedList<String>(); if (StringUtils.isNotEmpty(locale.getLanguage())) { components.add(locale.getLanguage().toLowerCase()); }//from w w w . j a v a 2 s . c om if (StringUtils.isNotEmpty(locale.getCountry())) { components.add(locale.getCountry().toLowerCase()); } if (StringUtils.isNotEmpty(locale.getVariant())) { components.add(locale.getVariant().toLowerCase()); } return StringUtils.join(components, "-"); }