List of usage examples for java.util Locale toString
@Override public final String toString()
Locale
object, consisting of language, country, variant, script, and extensions as below: language + "_" + country + "_" + (variant + "_#" | "#") + script + "_" + extensionsLanguage is always lower case, country is always upper case, script is always title case, and extensions are always lower case.
From source file:nz.co.senanque.localemanagement.XMLMessageSource.java
@Override protected MessageFormat resolveCode(String code, Locale locale) { String ret = null;/* ww w.j a va2s . co m*/ String country = locale.getCountry(); String language = locale.getLanguage(); String variant = locale.getVariant(); logger.debug("Code {} Initial locale {}", code, locale.toString()); Locale thisLocale = null; if (!StringUtils.isEmpty(variant)) { thisLocale = new Locale(language, country, variant); Map<String, String> m = m_map.get(thisLocale); if (m != null) { ret = m.get(code); } logger.debug("tried locale {} result: {}", thisLocale.toString(), ret); } if (ret == null) { if (!StringUtils.isEmpty(country)) { thisLocale = new Locale(language, country); Map<String, String> m = m_map.get(thisLocale); if (m != null) { ret = m.get(code); } logger.debug("tried locale {} result: {}", thisLocale.toString(), ret); } } if (ret == null) { if (!StringUtils.isEmpty(language)) { thisLocale = new Locale(language); Map<String, String> m = m_map.get(thisLocale); if (m != null) { ret = m.get(code); } logger.debug("tried locale {} result: {}", thisLocale.toString(), ret); } } if (ret == null) { thisLocale = Locale.getDefault(); Map<String, String> m = m_map.get(thisLocale); if (m != null) { ret = m.get(code); } logger.debug("tried locale {} result: {}", thisLocale.toString(), ret); } if (ret == null) { return null; } return new MessageFormat(ret, locale); }
From source file:it.cnr.icar.eric.client.ui.thin.UserPreferencesBean.java
/** Returns a Collection of available locales as SelectItems. */ public Collection<SelectItem> getSupportedLocalesSelectItems() { if (supportedLocalesSelectItems == null) { ArrayList<SelectItem> selectItems = new ArrayList<SelectItem>(); for (Iterator<Locale> it = getSupportedUiLocales().iterator(); it.hasNext();) { Locale loc = it.next(); SelectItem item = new SelectItem(loc.toString(), loc.getDisplayName(loc)); selectItems.add(item);/*from w ww . j a va2 s. c o m*/ } supportedLocalesSelectItems = selectItems; } return supportedLocalesSelectItems; }
From source file:org.eclipse.jubula.client.core.model.TestDataPO.java
/** * set the value for the given language/*w w w. ja va 2 s . c o m*/ * @param lang language, for which to set the value * @param value value */ private void setValue(Locale lang, String value) { if (value != null && value.length() != 0) { getMap().put(lang.toString(), value); } else { getMap().remove(lang.toString()); } }
From source file:org.apache.nutch.plugin.PluginDescriptor.java
/** * Returns a I18N'd resource string. The resource bundles could be stored in * root directory of a plugin in the well know i18n file name conventions. * //from w w w . j a va 2 s . com * @param pKey * @param pLocale * @return String * @throws IOException */ public String getResourceString(String pKey, Locale pLocale) throws IOException { if (fMessages.containsKey(pLocale.toString())) { ResourceBundle bundle = (ResourceBundle) fMessages.get(pLocale.toString()); try { return bundle.getString(pKey); } catch (MissingResourceException e) { return '!' + pKey + '!'; } } try { ResourceBundle res = ResourceBundle.getBundle("messages", pLocale, getClassLoader()); return res.getString(pKey); } catch (MissingResourceException x) { return '!' + pKey + '!'; } }
From source file:net.sf.ginp.GinpModel.java
/** * Sets the locale attribute of the GinpModel object. * *@param loc The new locale value/* ww w .ja v a 2 s. com*/ */ public final void setLocale(final Locale loc) { log.debug("setLocale: " + loc.toString()); if (Configuration.getForcelocale() != null) { if (Configuration.getForcelocale().equals("")) { locale = loc; } else { locale = new Locale(Configuration.getForcelocale()); } } else { locale = loc; } }
From source file:com.octo.captcha.engine.bufferedengine.buffer.MemoryCaptchaBuffer.java
/** * @see CaptchaBuffer#removeCaptcha(int, java.util.Locale) *///from w w w . j a v a 2s.co m public synchronized Collection removeCaptcha(int number, Locale locale) { ArrayList list = new ArrayList(number); UnboundedFifoBuffer buffer = (UnboundedFifoBuffer) buffers.get(locale); if (buffer == null) { logDebug("Locale not found in Memory buffer map : " + locale.toString()); return list; } try { for (int i = 0; i < number; i++) { list.add(buffer.remove()); } } catch (NoSuchElementException e) { // Stop retrieving captchas, used in order to use the "remove" without calling the expensive "size" method logDebug("Buffer empty for locale : " + locale.toString()); } logDebug("Removed from locale :'" + locale + "' a list of '" + list.size() + "' elements."); return list; }
From source file:de.sub.goobi.forms.SpracheForm.java
/** * The function getSupportedLocales() returns a list of maps, each * representing one locale configured in the faces-config.xml file. Each of * the maps will contain the fields. id the locales ID String, e.g. fr? * or en_GB? displayLanguageSelf the name of the language in the language * itself, e.g. English?, Deutsch?, franais?, espaol?, ???, * ?, //w w w . ja va 2 s.c o m * * <p> * Its a good practice to identify a language in its own spelling, since * this will be most likely what a speaker of that language will recognize. * See also: http://www.cs.tut.fi/~jkorpela/flags.html Note that * capitalisation is subject to the respective language. If the language is * unknown, the id will be returned. displayLanguageTranslated the name of * the language in the currently selected language, e.g., if the current * language is English: English?, German?, French?, * </p> * * <p> * This is just a nice feature because the language names are provided by * Java; and its used in the mouse-over titles, so you can find out what * e.g. ? means, even if you dont have a clue of the glyphs used. If * no translations are available, this will fall back to English. selected * whether this is the current language * </p> * * <p> * This can be used for a sophisticated layout. * </p> * * @return a list of maps, each with the fields id?, displayName? and * selected? */ public List<Map<String, Object>> getSupportedLocales() { List<Map<String, Object>> result = new ArrayList<>(); Locale currentDisplayLanguage = FacesContext.getCurrentInstance().getViewRoot().getLocale(); @SuppressWarnings("unchecked") // It seems we have an old Faces API, Faces 2.1s getSupportedLocales() // returns Iterator<Locale> // TODO: Update JSF API Iterator<Locale> localesIterator = FacesContext.getCurrentInstance().getApplication().getSupportedLocales(); while (localesIterator.hasNext()) { Locale supportedLocale = localesIterator.next(); if (supportedLocale.getLanguage().length() > 0) { Map<String, Object> translation = new HashMap<>(); translation.put("id", supportedLocale.toString()); translation.put("displayLanguageSelf", supportedLocale.getDisplayLanguage(supportedLocale)); translation.put("displayLanguageTranslated", supportedLocale.getDisplayLanguage(currentDisplayLanguage)); translation.put("selected", Boolean.valueOf(supportedLocale.equals(currentDisplayLanguage))); result.add(translation); } } return result; }
From source file:org.apache.tapestry.engine.DefaultComponentMessagesSource.java
private Properties readProperties(IResourceLocation baseLocation, String baseName, Locale locale, Properties parent) {/*from ww w . j a va2s .co m*/ StringBuffer buffer = new StringBuffer(baseName); if (locale != null) { buffer.append('_'); buffer.append(locale.toString()); } buffer.append(SUFFIX); IResourceLocation localized = baseLocation.getRelativeLocation(buffer.toString()); URL propertiesURL = localized.getResourceURL(); if (propertiesURL == null) return parent; Properties result = null; if (parent == null) result = new Properties(); else result = new Properties(parent); try { InputStream input = propertiesURL.openStream(); result.load(input); input.close(); } catch (IOException ex) { throw new ApplicationRuntimeException( Tapestry.format("ComponentPropertiesStore.unable-to-read-input", propertiesURL), ex); } return result; }
From source file:org.jboss.dashboard.kpi.KPIImpl.java
public void setDescription(String descr, Locale l) { if (l == null) l = LocaleManager.currentLocale(); if (descr == null) descriptions.remove(l.toString()); else {//from w w w .j a v a2s . co m descriptions.put(l.toString(), descr); DataDisplayer displayer = getDataDisplayer(); if (displayer instanceof AbstractChartDisplayer) { AbstractChartDisplayer chartDisplayer = (AbstractChartDisplayer) displayer; chartDisplayer.setTitle(descr); } } }
From source file:com.octo.captcha.engine.bufferedengine.buffer.MemoryCaptchaBuffer.java
/** * @see com.octo.captcha.engine.bufferedengine.buffer.CaptchaBuffer#putAllCaptcha(java.util.Collection) *//* w w w . ja v a 2 s . c o m*/ public synchronized void putAllCaptcha(Collection captchas, Locale locale) { if (!buffers.containsKey(locale)) { buffers.put(locale, new UnboundedFifoBuffer()); } ((UnboundedFifoBuffer) buffers.get(locale)).addAll(captchas); logDebug("put into mem : " + captchas.size() + " for locale :" + locale.toString() + " with size : " + ((UnboundedFifoBuffer) buffers.get(locale)).size()); }