List of usage examples for java.util Locale getDisplayVariant
public String getDisplayVariant(Locale inLocale)
From source file:Main.java
public static void main(String[] args) { Locale locale = new Locale("ENGLISH", "US", "WIN"); System.out.println("Locale:" + locale); // print display variant for locale - based on inLocale System.out.println("Variant:" + locale.getDisplayVariant(new Locale("GERMAN", "GERMANY", "MAC"))); }
From source file:org.opencms.workplace.commons.CmsPreferences.java
/** * Builds the html for the language select box of the start settings.<p> * /*w w w . ja v a 2 s .c o m*/ * @param htmlAttributes optional html attributes for the &lgt;select> tag * @return the html for the language select box */ public String buildSelectLanguage(String htmlAttributes) { // get available locales from the workplace manager List locales = OpenCms.getWorkplaceManager().getLocales(); List options = new ArrayList(locales.size()); List values = new ArrayList(locales.size()); int checkedIndex = 0; int counter = 0; Iterator i = locales.iterator(); Locale setLocale = getSettings().getUserSettings().getLocale(); while (i.hasNext()) { Locale currentLocale = (Locale) i.next(); // add all locales to the select box String language = currentLocale.getDisplayLanguage(setLocale); if (CmsStringUtil.isNotEmpty(currentLocale.getCountry())) { language = language + " (" + currentLocale.getDisplayCountry(setLocale) + ")"; } if (CmsStringUtil.isNotEmpty(currentLocale.getVariant())) { language = language + " (" + currentLocale.getDisplayVariant(setLocale) + ")"; } options.add(language); values.add(currentLocale.toString()); if (getParamTabWpLanguage().equals(currentLocale.toString())) { // mark the currently active locale checkedIndex = counter; } counter++; } return buildSelect(htmlAttributes, options, values, checkedIndex); }
From source file:org.orcid.frontend.web.util.LanguagesMap.java
/** * Returns the language translated in the given user locale * /*from w w w . j av a2 s. c o m*/ * @param locale * @param userLocal * * @return The language translated to the given locale. * */ @Cacheable(value = "languages-map", key = "#locale.toString() + '-' + #userLocale.toString()") public String buildLanguageValue(Locale locale, Locale userLocale) { if (userLocale != null && userLocale.getLanguage().equals("xx")) { return X; } String variant = locale.getVariant(); String displayVariant = locale.getDisplayVariant(userLocale); String language = WordUtils.capitalize(locale.getDisplayLanguage(userLocale)); if (StringUtils.isEmpty(variant)) if (StringUtils.isEmpty(locale.getDisplayCountry(userLocale))) return language; else return language + " (" + locale.getDisplayCountry(userLocale) + ')'; else if (StringUtils.isEmpty(locale.getDisplayCountry(userLocale))) return language + ' ' + displayVariant; else return language + ' ' + displayVariant + " (" + locale.getDisplayCountry(userLocale) + ')'; }
From source file:org.sakaiproject.util.ResourceLoader.java
/** ** Return a locale's display Name//from www .ja va 2 s . co m ** ** @return String used to display Locale ** ** @author Jean-Francois Leveque (Universite Pierre et Marie Curie - Paris 6) **/ public String getLocaleDisplayName(Locale loc) { Locale preferedLoc = getLocale(); StringBuilder displayName = new StringBuilder(loc.getDisplayLanguage(loc)); if (StringUtils.isNotBlank(loc.getDisplayCountry(loc))) { displayName.append(" - ").append(loc.getDisplayCountry(loc)); } if (StringUtils.isNotBlank(loc.getVariant())) { displayName.append(" (").append(loc.getDisplayVariant(loc)).append(")"); } displayName.append(" [").append(loc.toString()).append("] "); displayName.append(loc.getDisplayLanguage(preferedLoc)); if (StringUtils.isNotBlank(loc.getDisplayCountry(preferedLoc))) { displayName.append(" - ").append(loc.getDisplayCountry(preferedLoc)); } return displayName.toString(); }