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.jahia.services.render.URLResolver.java
private String getCacheKey(final String workspace, final Locale locale, final String path) { StringBuilder builder = new StringBuilder(workspace != null ? workspace : "null"); builder.append(CACHE_KEY_SEPARATOR); builder.append(locale != null ? locale.toString() : "null"); builder.append(CACHE_KEY_SEPARATOR); builder.append(path);//w w w . j a v a 2s .c o m return builder.toString(); }
From source file:org.dbflute.saflute.web.servlet.filter.RequestLoggingFilter.java
protected void buildRequestInfo(StringBuilder sb, HttpServletRequest request, HttpServletResponse response, boolean showResponse) { sb.append("Request class=" + request.getClass().getName()); sb.append(", RequestedSessionId=").append(request.getRequestedSessionId()); sb.append(LF).append(IND);//from w w w .j ava 2s. com sb.append(", REQUEST_URI=").append(request.getRequestURI()); sb.append(", SERVLET_PATH=").append(request.getServletPath()); sb.append(", CharacterEncoding=" + request.getCharacterEncoding()); sb.append(", ContentLength=").append(request.getContentLength()); sb.append(LF).append(IND); sb.append(", ContentType=").append(request.getContentType()); sb.append(", Locale=").append(request.getLocale()); sb.append(", Locales="); final Enumeration<?> locales = request.getLocales(); boolean first = true; while (locales.hasMoreElements()) { final Locale locale = (Locale) locales.nextElement(); if (first) { first = false; } else { sb.append(", "); } sb.append(locale.toString()); } sb.append(", Scheme=").append(request.getScheme()); sb.append(", isSecure=").append(request.isSecure()); sb.append(LF).append(IND); sb.append(", SERVER_PROTOCOL=").append(request.getProtocol()); sb.append(", REMOTE_ADDR=").append(request.getRemoteAddr()); sb.append(", REMOTE_HOST=").append(request.getRemoteHost()); sb.append(", SERVER_NAME=").append(request.getServerName()); sb.append(", SERVER_PORT=").append(request.getServerPort()); sb.append(LF).append(IND); sb.append(", ContextPath=").append(request.getContextPath()); sb.append(", REQUEST_METHOD=").append(request.getMethod()); sb.append(", PathInfo=").append(request.getPathInfo()); sb.append(", RemoteUser=").append(request.getRemoteUser()); sb.append(LF).append(IND); sb.append(", REQUEST_URL=").append(request.getRequestURL()); sb.append(LF).append(IND); sb.append(", QUERY_STRING=").append(request.getQueryString()); if (showResponse) { sb.append(LF).append(IND); buildResponseInfo(sb, request, response); } sb.append(LF); buildRequestHeaders(sb, request); buildRequestParameters(sb, request); buildCookies(sb, request); buildRequestAttributes(sb, request); buildSessionAttributes(sb, request); }
From source file:org.apache.cocoon.matching.LocaleMatcher.java
public Map match(final String pattern, Map objectModel, Parameters parameters) throws PatternException { final Map map = new HashMap(); I18nUtils.LocaleValidator validator = new I18nUtils.LocaleValidator() { public boolean test(String name, Locale locale) { if (getLogger().isDebugEnabled()) { getLogger().debug("Testing " + name + " locale: '" + locale + "'"); }//from w w w . j a v a2 s . co m return isValidResource(pattern, locale, map); } }; Locale locale = I18nUtils.findLocale(objectModel, localeAttribute, parameters, defaultLocale, useLocale, useLocales, useBlankLocale, validator); if (locale == null) { if (getLogger().isDebugEnabled()) { getLogger().debug("No locale found for resource: " + pattern); } return null; } String localeStr = locale.toString(); if (getLogger().isDebugEnabled()) { getLogger().debug("Locale " + localeStr + " found for resource: " + pattern); } I18nUtils.storeLocale(objectModel, localeAttribute, localeStr, storeInRequest, storeInSession, storeInCookie, createSession); return map; }
From source file:com.etalio.android.EtalioBase.java
protected String getEtalioUserAgent() { Locale locale = Locale.getDefault(); Resources resources;/*www. ja v a2s.co m*/ resources = mContext.getApplicationContext().getResources(); return "Etalio/" + getVersion() + " (Linux; " + " Android " + Build.VERSION.RELEASE + "; " + locale.toString() + "; " + Build.MANUFACTURER + " " + Build.MODEL + " Build/" + Build.DISPLAY + "; " + " Density/" + (resources != null ? resources.getDisplayMetrics().density : "unknown") + ")"; }
From source file:org.alfresco.repo.model.ml.MultilingualContentServiceImpl.java
/** {@inheritDoc} */ public List<Locale> getMissingTranslations(NodeRef localizedNodeRef, boolean addThisNodeLocale) { List<Locale> foundLocales = new ArrayList<Locale>(getTranslations(localizedNodeRef).keySet()); List<String> foundLanguages = new ArrayList<String>(); // transform locales into languages codes for (Locale locale : foundLocales) { foundLanguages.add(locale.getLanguage()); }//from w w w .j a va 2 s.co m // add the locale of the given node if required if (addThisNodeLocale) { Locale localeNode = (Locale) nodeService.getProperty(localizedNodeRef, ContentModel.PROP_LOCALE); if (localeNode != null) { foundLanguages.remove(localeNode.toString()); } else { logger.warn("No locale found for the node " + localizedNodeRef); } } List<String> missingLanguages = null; if (foundLanguages.size() == 0) { // The given node is the only one available translation and it must // be return. // MissingLanguages become the entire list pf languages. missingLanguages = contentFilterLanguagesService.getFilterLanguages(); } else { // get the missing languages form the list of content filter languages missingLanguages = contentFilterLanguagesService.getMissingLanguages(foundLanguages); } // construct a list of locales List<Locale> missingLocales = new ArrayList<Locale>(missingLanguages.size() + 1); for (String lang : missingLanguages) { missingLocales.add(I18NUtil.parseLocale(lang)); } return missingLocales; }
From source file:org.alfresco.repo.search.impl.lucene.LuceneQueryParser.java
protected void addLocaleSpecificUntokenisedMLOrTextFunction(String expandedFieldName, String queryText, LuceneFunction luceneFunction, BooleanQuery booleanQuery, MLAnalysisMode mlAnalysisMode, Locale locale, IndexTokenisationMode tokenisationMode) { String textFieldName = expandedFieldName; if (tokenisationMode == IndexTokenisationMode.BOTH) { if (locale.toString().length() == 0) { textFieldName = textFieldName + FIELD_NO_LOCALE_SUFFIX; } else {/* w w w .j a va 2 s. c om*/ textFieldName = textFieldName + "." + locale + FIELD_SORT_SUFFIX; } } String termText = queryText; if (locale.toString().length() > 0) { termText = "{" + locale + "}" + queryText; } Query subQuery = buildFunctionQuery(textFieldName, termText, luceneFunction); booleanQuery.add(subQuery, Occur.SHOULD); if (booleanQuery.getClauses().length == 0) { booleanQuery.add(createNoMatchQuery(), Occur.SHOULD); } }
From source file:org.alfresco.repo.model.ml.MultilingualContentServiceImpl2.java
/** {@inheritDoc} */ public List<Locale> getMissingTranslations(NodeRef localizedNodeRef, boolean addThisNodeLocale) { List<Locale> foundLocales = new ArrayList<Locale>(getTranslations(localizedNodeRef).keySet()); List<String> foundLanguages = new ArrayList<String>(); // transform locales into languages codes for (Locale locale : foundLocales) { foundLanguages.add(locale.getLanguage()); }//from w ww. j a va 2 s . c om // add the locale of the given node if required if (addThisNodeLocale) { Locale localeNode = (Locale) nodeService.getProperty(localizedNodeRef, ContentModel.PROP_LOCALE); if (localeNode != null) { foundLanguages.remove(localeNode.toString()); } else { logger.warn("No locale found for the node " + localizedNodeRef); } } List<String> missingLanguages = null; if (foundLanguages.size() == 0) { // The given node is the only one available translation and it must // be return. // MissingLanguages become the entire list pf languages. missingLanguages = contentFilterLanguagesService.getFilterLanguages(); } else { // get the missing languages form the list of content filter // languages missingLanguages = contentFilterLanguagesService.getMissingLanguages(foundLanguages); } // construct a list of locales List<Locale> missingLocales = new ArrayList<Locale>(missingLanguages.size() + 1); for (String lang : missingLanguages) { missingLocales.add(I18NUtil.parseLocale(lang)); } return missingLocales; }
From source file:com.redhat.rhn.common.localization.LocalizationService.java
/** * Get a localized version of a string with the specified locale. * @param messageId The key of the message we are fetching * @param locale The locale to use when fetching the string * @param args arguments for message.// w w w . j a v a2s . co m * @return Translated String */ public String getMessage(String messageId, Locale locale, Object... args) { log.debug("getMessage() called with messageId: " + messageId + " and locale: " + locale); // Short-circuit the rest of the method if the messageId is null // See bz 199892 if (messageId == null) { return getMissingMessageString(messageId); } String userLocale = locale == null ? "null" : locale.toString(); if (msgLogger.isDebugEnabled()) { msgLogger.debug("Resolving message \"" + messageId + "\" for locale " + userLocale); } String mess = null; Class z = null; try { // If the keyMap doesn't contain the requested key // then there is no hope and we return. if (!keyToBundleMap.containsKey(messageId)) { return getMissingMessageString(messageId); } z = Class.forName(keyToBundleMap.get(messageId)); // If we already determined that there aren't an bundles // for this Locale then we shouldn't repeatedly fail // attempts to parse the bundle. Instead just force a // call to the default Locale. mess = XmlMessages.getInstance().format(z, locale, messageId, args); } catch (MissingResourceException e) { // Try again with DEFAULT_LOCALE if (msgLogger.isDebugEnabled()) { msgLogger.debug("Resolving message \"" + messageId + "\" for locale " + userLocale + " failed - trying again with default " + "locale " + DEFAULT_LOCALE.toString()); } try { mess = XmlMessages.getInstance().format(z, DEFAULT_LOCALE, messageId, args); } catch (MissingResourceException mre) { if (msgLogger.isDebugEnabled()) { msgLogger.debug("Resolving message \"" + messageId + "\" " + "for default locale " + DEFAULT_LOCALE.toString() + " failed"); } return getMissingMessageString(messageId); } } catch (ClassNotFoundException ce) { String message = "Class not found when trying to fetch a message: " + ce.toString(); log.error(message, ce); throw new LocalizationException(message, ce); } return getDebugVersionOfString(mess); }
From source file:com.jfinal.core.Controller.java
/** * Write Local to cookie/*from w ww . j a v a 2s. c o m*/ */ public Controller setLocaleToCookie(Locale locale) { setCookie(I18N_LOCALE, locale.toString(), I18N.getI18nMaxAgeOfCookie()); return this; }
From source file:org.atomserver.core.dbstore.DBBasedAtomCollection.java
private void addPagingLinks(Feed feed, IRI iri, long endIndex, int pageSize, URITarget uriTarget, boolean noLatency) { String nextURI = iri.getPath() + "?" + QueryParam.startIndex.getParamName() + "=" + endIndex + "&" + QueryParam.maxResults.getParamName() + "=" + pageSize; Locale locale = uriTarget.getLocaleParam(); if (locale != null) { nextURI += "&" + QueryParam.locale.getParamName() + "=" + locale.toString(); }//www .j av a 2s . co m EntryType entryType = uriTarget.getEntryTypeParam(); if (entryType != null) { nextURI += "&" + QueryParam.entryType.getParamName() + "=" + entryType.toString(); } // NOTE: we do NOT add the updated-min param because, by definition, we have already satisfied that // condition on the first page of this page set. (i.e. we're past that point) // And passing along start-index ensures this. Date updatedMax = uriTarget.getUpdatedMaxParam(); if (updatedMax != null) { nextURI += "&" + QueryParam.updatedMax.getParamName() + "=" + AtomDate.format(updatedMax); } long endIndexMax = uriTarget.getEndIndexParam(); if (endIndexMax != -1L) { nextURI += "&" + QueryParam.endIndex.getParamName() + "=" + endIndexMax; } if (noLatency) { nextURI += "&" + QueryParam.noLatency.getParamName() + "=" + noLatency; } FeedPagingHelper.setNext(feed, nextURI); }