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:org.enerj.apache.commons.beanutils.locale.LocaleConvertUtilsBean.java
/** * Convert the specified value to an object of the specified class (if * possible) using the convertion pattern. Otherwise, return a String * representation of the value./*from w ww . jav a2s.c om*/ * * @param value The String scalar value to be converted * @param clazz The Data type to which this value should be converted. * @param locale The locale * @param pattern The convertion pattern * * @exception ConversionException if thrown by an underlying Converter */ public Object convert(String value, Class clazz, Locale locale, String pattern) { if (log.isDebugEnabled()) { log.debug("Convert string " + value + " to class " + clazz.getName() + " using " + locale.toString() + " locale and " + pattern + " pattern"); } LocaleConverter converter = lookup(clazz, locale); if (converter == null) { converter = (LocaleConverter) lookup(String.class, locale); } if (log.isTraceEnabled()) { log.trace(" Using converter " + converter); } return (converter.convert(clazz, value, pattern)); }
From source file:org.atomserver.uri.URIHandler.java
/** * Construct the filename portion of the URI * The URI filename looks like this; </p> * [entryId].[locale].xml (e.g. 1234.en_GB.xml)</p> * where locale is optional.//www.j a v a 2 s . co m * @param entryId Required * @param locale May be null * @return The filename portion of the URI */ public String constructFileName(String entryId, Locale locale) { return locale != null ? (entryId + "." + locale.toString() + ".xml") : (entryId + ".xml"); }
From source file:com.bibisco.manager.LocaleManager.java
private Locale initLocale() { Locale lLocale = null; mLog.debug("Start initLocale()"); PropertiesManager lPropertiesManager = PropertiesManager.getInstance(); String lStrLocale = lPropertiesManager.getProperty("locale"); if (StringUtils.isNotBlank(lStrLocale)) { String[] lStrLocaleSplit = lStrLocale.split("_"); lLocale = new Locale(lStrLocaleSplit[0], lStrLocaleSplit[1]); } else {/*from w w w . j a v a2s . c o m*/ lLocale = Locale.getDefault(); lPropertiesManager.updateProperty("locale", lLocale.toString()); } mLog.debug("End initLocale()"); return lLocale; }
From source file:org.b3log.latke.plugin.AbstractPlugin.java
/** * Gets language label with the specified locale and key. * /* w w w . j a v a 2s. c o m*/ * @param locale the specified locale * @param key the specified key * @return language label */ public String getLang(final Locale locale, final String key) { return langs.get(locale.toString()).getProperty(key); }
From source file:com.bstek.dorado.view.resolver.PackageFileResolver.java
@Override protected String getResourceCacheKey(HttpServletRequest request) throws Exception { Locale locale = localeResolver.resolveLocale(); if (locale == null) { locale = defaultLocale;// w ww. j av a2 s .c o m } return getRelativeRequestURI(request) + "|" + locale.toString(); }
From source file:org.apache.tiles.definition.UrlDefinitionsFactory.java
/** * Appends locale-specific {@link Definition} objects to an existing * {@link Definitions} set by reading locale-specific versions of * the applied sources.//from w w w .j av a 2 s. co m * * @param definitions The Definitions object to append to. * @param tilesContext The requested locale. * @throws DefinitionsFactoryException if an error occurs reading definitions. * @deprecated Let the definitions be loaded by a {@link DefinitionDAO}. */ @Deprecated protected void addDefinitions(Definitions definitions, TilesRequestContext tilesContext) { Locale locale = localeResolver.resolveLocale(tilesContext); Map<String, Definition> defsMap = definitionDao.getDefinitions(locale); if (defsMap == null) { throw new NullPointerException("There are no definitions mapped to locale '" + locale.toString() + "'"); } }
From source file:org.eclipse.jubula.client.core.model.ProjectPropertiesPO.java
/** * @param defaultLanguage The defaultLanguage to set. *//*from www. j a va 2s . c o m*/ public void setDefaultLanguage(Locale defaultLanguage) { Validate.notNull(defaultLanguage); setHbmDefaultLanguage(defaultLanguage.toString()); }
From source file:org.ajax4jsf.context.AjaxContextImpl.java
/** * Encode declaration for AJAX response. Render <html><body> * //from ww w . ja v a 2 s . c om * @param context * @throws IOException */ public void encodeAjaxBegin(FacesContext context) throws IOException { UIViewRoot viewRoot = context.getViewRoot(); // AjaxContainer ajax = (AjaxContainer) component; ResponseWriter out = context.getResponseWriter(); // DebugUtils.traceView("ViewRoot in AJAX Page encode begin"); out.startElement(HTML.HTML_ELEMENT, viewRoot); Locale locale = viewRoot.getLocale(); out.writeAttribute(HTML.lang_ATTRIBUTE, locale.toString(), "lang"); out.startElement(HTML.BODY_ELEMENT, viewRoot); }
From source file:com.aurel.track.lucene.index.listFields.LocalizedListIndexer.java
/** * Creates a localized lookup document.//w w w .j av a 2 s .c om * @param localizedLabelBean * @param type * @return */ @Override protected Document createDocument(ILabelBean labelBean, int type) { ILocalizedLabelBean localizedLabelBean = (ILocalizedLabelBean) labelBean; String id = localizedLabelBean.getObjectID().toString(); String notLocalizedName = localizedLabelBean.getLabel(); String keyPrefix = localizedLabelBean.getKeyPrefix(); Document document = new Document(); try { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Creating the localized list option document by id " + id + " not localized name " + notLocalizedName + " type " + String.valueOf(type)); } if (countrySet != null && !countrySet.isEmpty()) { String key = keyPrefix + id; String defaultLocalizedName = null; if (defaultLocale != null) { defaultLocalizedName = LocalizeUtil.getLocalizedTextFromApplicationResources(key, defaultLocale); if (defaultLocalizedName != null && !defaultLocalizedName.equals(notLocalizedName)) { if (defaultLocalizedName.equals(key)) { //no default localization defaultLocalizedName = notLocalizedName; } else { document.add(new TextField(LuceneUtil.LIST_INDEX_FIELDS_LOCALIZED.DEFAULT_LOCALIZED, defaultLocalizedName, Field.Store.NO)); if (LOGGER.isDebugEnabled()) { LOGGER.debug(" defaultLocalizedName " + defaultLocalizedName); } } } } Map<String, String> localizedNameMap = new HashMap<String, String>(); for (Locale locale : languageSet) { String localizedName = LocalizeUtil.getLocalizedTextFromApplicationResources(key, locale); if (localizedName != null && !localizedName.equals(key) && !localizedName.equals(defaultLocalizedName)) { localizedNameMap.put(locale.toString(), localizedName); //locale specific label which differs from the default localization (fallbacks to default will not be stored) document.add(new TextField(locale.toString(), localizedName, Field.Store.NO)); if (LOGGER.isDebugEnabled()) { LOGGER.debug(" localizedName for locale " + locale.toString() + " " + localizedName); } } } for (Locale locale : countrySet) { String localizedName = LocalizeUtil.getLocalizedTextFromApplicationResources(key, locale); if (localizedName != null && !localizedName.equals(key) && !localizedName.equals(defaultLocalizedName)) { String localeStr = locale.toString(); if (localeStr != null && localeStr.length() >= 2) { String countryString = localeStr.substring(0, 2); String languageLocalizedName = localizedNameMap.get(countryString); if (languageLocalizedName == null || !languageLocalizedName.equals(localizedName)) { //locale specific label which differs from the default localization (fallbacks to default will not be stored) document.add(new TextField(locale.toString(), localizedName, Field.Store.NO)); if (LOGGER.isDebugEnabled()) { LOGGER.debug( " localizedName for locale " + locale.toString() + " " + localizedName); } } } } } } //COMBINEDKEY used only by delete, because it works only with Term (BooleanQuery not possible) document.add(new StringField(LuceneUtil.LIST_INDEX_FIELDS_LOCALIZED.COMBINEDKEY, LuceneUtil.getCombinedKeyValue(id, String.valueOf(type)), Field.Store.YES)); document.add(new StringField(LuceneUtil.LIST_INDEX_FIELDS_LOCALIZED.VALUE, id, Field.Store.YES)); document.add( new TextField(LuceneUtil.LIST_INDEX_FIELDS_LOCALIZED.LABEL, notLocalizedName, Field.Store.NO)); document.add(new StringField(LuceneUtil.LIST_INDEX_FIELDS_LOCALIZED.TYPE, String.valueOf(type), Field.Store.YES)); return document; } catch (Exception e) { LOGGER.error("Creating the document for localized list entry with keyPrefix " + keyPrefix + " label " + notLocalizedName + " id " + id + " Type " + type + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); return null; } }
From source file:org.kitodo.production.forms.LanguageForm.java
/** * The procedure switchLanguage is used to alter the applications interface * language./*w w w . j a va2s . co m*/ * * @param langCodeCombined * This parameter can be either of form language? or of form * language_country?, e.g. en? or en_GB? are valid values. */ public void switchLanguage(String langCodeCombined) throws IOException { String[] languageCode = langCodeCombined.split("_"); Locale locale; if (languageCode.length == 2) { locale = new Locale(languageCode[0], languageCode[1]); } else { locale = new Locale(languageCode[0]); } try { User user = ServiceManager.getUserService() .getById(ServiceManager.getUserService().getAuthenticatedUser().getId()); user.setLanguage(locale.toString()); ServiceManager.getUserService().saveToDatabase(user); } catch (DAOException e) { Helper.setErrorMessage("Error in saving user", logger, e); } FacesContext context = FacesContext.getCurrentInstance(); context.getViewRoot().setLocale(locale); context.getExternalContext().getSessionMap().put(SESSION_LOCALE_FIELD_ID, locale); // Reload current page to make language change effective context.getExternalContext() .redirect(((HttpServletRequest) context.getExternalContext().getRequest()).getRequestURI()); }