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:com.properned.application.LocaleListCell.java
@Override protected void updateItem(Locale locale, boolean empty) { super.updateItem(locale, empty); setGraphic(null);//from ww w . jav a 2 s .com setText(null); if (locale != null) { String localeToString = locale.toString(); if (localeToString.isEmpty()) { localeToString = MessageReader.getInstance().getMessage("locale.default"); } if (StringUtils.isNotEmpty(locale.getDisplayName())) { localeToString += " (" + locale.getDisplayName() + ")"; } setText(localeToString); MenuItem deleteMenu = getDeleteMenu(locale); this.setContextMenu(new ContextMenu(deleteMenu)); } }
From source file:org.keyboardplaying.xtt.ui.i18n.I18nHelper.java
/** * Returns a list of all locales a bundle has been written for. * * @return a list of all locales availables within the application *//*from w ww. j ava2s.com*/ public List<Locale> getAvailableLocales() { /* Convert base name to a path. */ String bundlePath = BUNDLE_BASE_NAME.replaceAll("\\.", "/") + "_%s.properties"; List<Locale> available = new ArrayList<>(); /* Loop over all locales to find those we do support. */ // Get a list of all locales the JVM supports Locale[] locales = Locale.getAvailableLocales(); // Loop over those to find available locales for (Locale locale : locales) { URL bundleUrl = ClassLoader.getSystemResource(String.format(bundlePath, locale.toString())); if (bundleUrl != null) { available.add(locale); } } /* Return the list. */ return available; }
From source file:org.alfresco.repo.search.impl.lucene.analysis.MLTokenDuplicator.java
/** * * @param locale/*www .j a va2 s .com*/ * @param mlAnalysisMode */ public MLTokenDuplicator(Locale locale, MLAnalysisMode mlAnalysisMode) { this.locale = locale; Collection<Locale> locales = MLAnalysisMode.getLocales(mlAnalysisMode, locale, false); prefixes = new HashSet<String>(locales.size()); for (Locale toAdd : locales) { String localeString = toAdd.toString(); if (localeString.length() == 0) { prefixes.add(""); } else { StringBuilder builder = new StringBuilder(16); builder.append("{").append(localeString).append("}"); prefixes.add(builder.toString()); } } if (s_logger.isDebugEnabled()) { s_logger.debug("Locale " + locale + " using " + mlAnalysisMode + " is " + prefixes); } }
From source file:com.couchbase.lite.CollationTest.java
public void testCollateJapaneseStrings() { int mode = kJsonCollator_Unicode; // en_US//ww w . j ava 2 s .c o m Collator c = Collator.getInstance(new Locale("en_US")); Assert.assertEquals(-1, SQLiteJsonCollator.testCollate(mode, encode("?"), encode("?"))); Assert.assertEquals(1, SQLiteJsonCollator.testCollate(mode, encode("?"), encode("?"))); Assert.assertEquals(0, SQLiteJsonCollator.testCollate(mode, encode("?"), encode("?"))); Assert.assertEquals(c.compare("", ""), SQLiteJsonCollator.testCollate(mode, encode(""), encode(""))); Assert.assertEquals(c.compare("?", ""), SQLiteJsonCollator.testCollate(mode, encode("?"), encode(""))); Assert.assertEquals(c.compare("?", ""), SQLiteJsonCollator.testCollate(mode, encode("?"), encode(""))); Assert.assertEquals(c.compare("", ""), SQLiteJsonCollator.testCollate(mode, encode(""), encode(""))); Assert.assertEquals(c.compare("", "?"), SQLiteJsonCollator.testCollate(mode, encode(""), encode("?"))); Assert.assertEquals(c.compare("", "?"), SQLiteJsonCollator.testCollate(mode, encode(""), encode("?"))); Assert.assertEquals(c.compare("", ""), SQLiteJsonCollator.testCollate(mode, encode(""), encode(""))); // ja Locale locale = new Locale("ja"); String localeStr = locale.toString(); Collator c1 = Collator.getInstance(locale); Assert.assertEquals(-1, SQLiteJsonCollator.testCollate(mode, localeStr, encode("?"), encode("?"))); Assert.assertEquals(1, SQLiteJsonCollator.testCollate(mode, localeStr, encode("?"), encode("?"))); Assert.assertEquals(0, SQLiteJsonCollator.testCollate(mode, localeStr, encode("?"), encode("?"))); Assert.assertEquals(c1.compare("", ""), SQLiteJsonCollator.testCollate(mode, localeStr, encode(""), encode(""))); Assert.assertEquals(c1.compare("?", ""), SQLiteJsonCollator.testCollate(mode, localeStr, encode("?"), encode(""))); Assert.assertEquals(c1.compare("?", ""), SQLiteJsonCollator.testCollate(mode, localeStr, encode("?"), encode(""))); Assert.assertEquals(c1.compare("", ""), SQLiteJsonCollator.testCollate(mode, localeStr, encode(""), encode(""))); Assert.assertEquals(c1.compare("", "?"), SQLiteJsonCollator.testCollate(mode, localeStr, encode(""), encode("?"))); Assert.assertEquals(c1.compare("", "?"), SQLiteJsonCollator.testCollate(mode, localeStr, encode(""), encode("?"))); Assert.assertEquals(c1.compare("", ""), SQLiteJsonCollator.testCollate(mode, localeStr, encode(""), encode(""))); }
From source file:org.alfresco.repo.search.impl.lucene.analysis.MLTokenDuplicator.java
public MLTokenDuplicator(TokenStream source, Locale locale, Reader reader, MLAnalysisMode mlAnalysisMode) { this.source = source; this.locale = locale; Collection<Locale> locales = MLAnalysisMode.getLocales(mlAnalysisMode, locale, false); prefixes = new HashSet<String>(locales.size()); for (Locale toAdd : locales) { String localeString = toAdd.toString(); if (localeString.length() == 0) { prefixes.add(""); } else {/*from w w w . j a v a 2s .co m*/ StringBuilder builder = new StringBuilder(16); builder.append("{").append(localeString).append("}"); prefixes.add(builder.toString()); } } if (s_logger.isDebugEnabled()) { s_logger.debug("Locale " + locale + " using " + mlAnalysisMode + " is " + prefixes); } }
From source file:org.apereo.portal.layout.dlm.remoting.registry.v43.PortletDefinitionBean.java
private PortletDefinitionBean(final MarketplacePortletDefinition mpd, final Locale locale) { this.id = mpd.getPortletDefinitionId().getLongId(); this.fname = mpd.getFName(); this.title = mpd.getTitle(locale.toString()); this.name = mpd.getName(locale.toString()); this.description = mpd.getDescription(locale.toString()); this.state = mpd.getLifecycleState().toString(); this.typeId = mpd.getType().getId(); this.averageRating = mpd.getRating(); this.ratingsCount = mpd.getUsersRated(); this.parameters = new HashMap<>(mpd.getParametersAsUnmodifiableMap()); this.keywords = mpd.getKeywords() != null ? Collections.unmodifiableList(mpd.getKeywords()) : EMPTY_KEYWORDS;/* ww w. ja v a 2 s . com*/ }
From source file:org.b3log.solo.processor.InitProcessor.java
/** * Initializes B3log Solo./*from w ww .j ava 2 s . c o m*/ * * @param context the specified http request context * @param request the specified http servlet request, for example, * <pre> * { * "userName": "", * "userEmail": "", * "userPassword": "" * } * </pre> * @param response the specified http servlet response * @throws Exception exception */ @RequestProcessing(value = "/init", method = HTTPRequestMethod.POST) public void initB3logSolo(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response) throws Exception { if (SoloServletListener.isInited()) { response.sendRedirect("/"); return; } final JSONRenderer renderer = new JSONRenderer(); context.setRenderer(renderer); final JSONObject ret = QueryResults.defaultResult(); renderer.setJSONObject(ret); try { final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response); final String userName = requestJSONObject.optString(User.USER_NAME); final String userEmail = requestJSONObject.optString(User.USER_EMAIL); final String userPassword = requestJSONObject.optString(User.USER_PASSWORD); if (Strings.isEmptyOrNull(userName) || Strings.isEmptyOrNull(userEmail) || Strings.isEmptyOrNull(userPassword) || !Strings.isEmail(userEmail)) { ret.put(Keys.MSG, "Init failed, please check your input"); return; } final Locale locale = Locales.getLocale(request); requestJSONObject.put(Keys.LOCALE, locale.toString()); initService.init(requestJSONObject); // If initialized, login the admin final JSONObject admin = new JSONObject(); admin.put(User.USER_NAME, requestJSONObject.getString(User.USER_NAME)); admin.put(User.USER_EMAIL, requestJSONObject.getString(User.USER_EMAIL)); admin.put(User.USER_ROLE, Role.ADMIN_ROLE); admin.put(User.USER_PASSWORD, requestJSONObject.getString(User.USER_PASSWORD)); Sessions.login(request, response, admin); ret.put(Keys.STATUS_CODE, true); } catch (final Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); ret.put(Keys.MSG, e.getMessage()); } }
From source file:facebook4j.TargetingParameter.java
public TargetingParameter locale(Locale locale) { if (locales == null) { locales = new LinkedHashSet<String>(); }//w ww . j a v a2s . co m locales.add(locale.toString()); return this; }
From source file:com.redhat.rhn.frontend.action.help.DocSearchSetupAction.java
private List performSearch(Long sessionId, String searchString, String mode, HttpServletRequest request) throws XmlRpcFault, MalformedURLException { log.debug("Performing doc search"); // call search server XmlRpcClient client = new XmlRpcClient(ConfigDefaults.get().getSearchServerUrl(), true); List args = new ArrayList(); args.add(sessionId);/*from w w w . j av a 2s . c o m*/ args.add("docs"); args.add(preprocessSearchString(searchString, mode)); // get lang we are searching in Locale l = Context.getCurrentContext().getLocale(); args.add(l.toString()); Boolean searchFreeForm = false; if (OPT_FREE_FORM.equals(mode)) { // adding a boolean of true to signify we want the results to be // constrained to closer matches, this will force the Lucene Queries // to use a "MUST" instead of the default "SHOULD". It will not // allow fuzzy matches as in spelling errors, but it will allow // free form searches to do more advanced options //args.add(true); searchFreeForm = true; } args.add(searchFreeForm); List results = Collections.emptyList(); try { results = (List) client.invoke("index.search", args); } catch (XmlRpcFault e) { if (e.getErrorCode() == 200) { //This is most likely a language error //so lets try the search the default language //removing the 'lang' from the args args.remove(args.size() - 2); results = (List) client.invoke("index.search", args); List<ValidatorWarning> warnings = new LinkedList<ValidatorWarning>(); warnings.add(new ValidatorWarning("packages.search.index_files_missing_for_docs")); getStrutsDelegate().saveMessages(request, Collections.EMPTY_LIST, warnings); } else { throw e; } } if (log.isDebugEnabled()) { log.debug("results = [" + results + "]"); } if (results.isEmpty()) { return Collections.emptyList(); } List<HelpDocumentOverview> docs = new ArrayList<HelpDocumentOverview>(); for (int x = 0; x < results.size(); x++) { HelpDocumentOverview doc = new HelpDocumentOverview(); Map item = (Map) results.get(x); log.debug("SearchServer sent us item [" + item.get("rank") + "], score = " + item.get("score") + ", summary = " + item.get("summary") + ", title = " + item.get("title") + ", url = " + item.get("url")); doc.setUrl((String) item.get("url")); doc.setTitle((String) item.get("title")); doc.setSummary((String) item.get("summary")); docs.add(doc); } return docs; }
From source file:com.wisemapping.filter.UserLocaleInterceptor.java
public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, Object object) throws Exception { final HttpSession session = request.getSession(false); User user = Utils.getUser(false);//from www . j a va 2 s . co m if (user != null && session != null) { String userLocale = user.getLocale(); final Locale sessionLocale = (Locale) session .getAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME); if ((userLocale != null) && ((sessionLocale == null) || (!userLocale.equals(sessionLocale.toString())))) { Locale locale; if (userLocale.contains("_")) { final String[] spit = userLocale.split("_"); locale = new Locale(spit[0], spit[1]); } else { locale = new Locale(userLocale); } session.setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, locale); } } return true; }