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:fr.hoteia.qalingo.core.i18n.message.impl.CoreMessageSourceImpl.java
public String getMessage(final MessageSourceResolvable resolvable, final Locale locale) throws NoSuchMessageException { try {// w w w. j av a 2 s. c o m return messageSource.getMessage(resolvable, locale); } catch (Exception e) { LOG.error("This message key doesn't exist: " + resolvable.getCodes() + ", for this locale: " + locale.toString()); if (BooleanUtils.negate(locale.toString().equalsIgnoreCase(Constants.DEFAULT_LOCALE_CODE))) { return getMessage(resolvable, new Locale(Constants.DEFAULT_LOCALE_CODE)); } } return null; }
From source file:fr.hoteia.qalingo.core.i18n.message.impl.CoreMessageSourceImpl.java
public String getMessage(final String code, final Object args[], final String defaultMessage, final Locale locale) { try {// w w w.ja va 2 s.c om return messageSource.getMessage(code, args, defaultMessage, locale); } catch (Exception e) { if (code != null && code.contains("javax")) { LOG.warn("This message key doesn't exist: " + code + ", for this locale: " + locale.toString()); } else { LOG.error("This message key doesn't exist: " + code + ", for this locale: " + locale.toString()); } if (BooleanUtils.negate(locale.toString().equalsIgnoreCase(Constants.DEFAULT_LOCALE_CODE))) { return getMessage(code, args, defaultMessage, new Locale(Constants.DEFAULT_LOCALE_CODE)); } } return null; }
From source file:com.bstek.dorado.console.runtime.DoradoConfigController.java
public void onViewInit(Label description, Container buttonsContainer, AutoForm propertiesConfigAutoForm, View view) {//from ww w . j a v a2 s.c om HttpServletRequest req = DoradoContext.getAttachedRequest(); Locale locale = DoradoContext.getAttachedRequest().getLocale(); initializeCacheWebConfigMap(); String type = req.getParameter("type"); Map<String, Object> map = new HashMap<String, Object>(); AutoFormElement element = null; ConfigureStore store = Configure.getStore(); if (locale.toString().equals(DEFAULT_LOCALE)) { description.setText("?????"); } else { description.setText("Global configuration items in non-editable runtime."); } if (type.equals("WebConfigure")) { buttonsContainer.setVisible(true); store = WebConfigure.getStore(); if (locale.toString().equals(DEFAULT_LOCALE)) { description.setText("Web???,?Session"); } else { description.setText( "Web configuration can be compiled at run time, and scope is the current Session."); } } Set<String> keySet = store.keySet(); Iterator<String> iterator = keySet.iterator(); while (iterator.hasNext()) { String key = (String) iterator.next(); if (type.equals("WebConfigure") && !properties.contains(key)) { continue; } String id = key.replace('.', '_'); Object value = store.get(key); element = new AutoFormElement(); element.setId(id); element.setLabel(key); element.setLabelWidth(320); element.setReadOnly(!(type.equals("WebConfigure") && properties.contains(key))); if ("core.contextConfigLocation".equals(key) || "core.servletContextConfigLocation".equals(key)) { element.setHeight("100"); element.setEditor(new TextArea()); String valueStr = (String) value; value = valueStr.replaceAll(";", ";\n"); } propertiesConfigAutoForm.addElement(element); map.put(id, value); } view.setUserData(map); }
From source file:org.jboss.dashboard.displayer.AbstractDataDisplayerXMLFormat.java
protected void formatDomain(DomainConfiguration config, PrintWriter out, int indent) { printIndent(out, indent);/*from w ww. j a va 2 s.co m*/ out.print("<propertyid>"); out.print(StringEscapeUtils.escapeXml(config.getPropertyId())); out.println("</propertyid>"); Map<Locale, String> domainNames = config.getPropertyNameI18nMap(); for (Locale locale : domainNames.keySet()) { printIndent(out, indent); out.print("<name language"); out.print("=\"" + StringEscapeUtils.escapeXml(locale.toString()) + "\">"); out.print(StringEscapeUtils.escapeXml(domainNames.get(locale))); out.println("</name>"); } printIndent(out, indent); out.print("<maxnumberofintervals>"); out.print(StringEscapeUtils.escapeXml(String.valueOf(config.getMaxNumberOfIntervals()))); out.println("</maxnumberofintervals>"); // Label domain specifics. Domain domain = config.getDomainProperty().getDomain(); if (domain instanceof LabelDomain) { Map<Locale, String> intervalsToHide = config.getLabelIntervalsToHideI18nMap(); for (Locale locale : intervalsToHide.keySet()) { printIndent(out, indent); out.print("<intervalstohide language"); out.print("=\"" + StringEscapeUtils.escapeXml(locale.toString()) + "\">"); out.print(StringEscapeUtils.escapeXml(intervalsToHide.get(locale))); out.println("</intervalstohide>"); } } else if (domain instanceof DateDomain) { if (config.getDateTamInterval() != null) { printIndent(out, indent); out.print("<taminterval>"); out.print(StringEscapeUtils.escapeXml(String.valueOf(config.getDateTamInterval()))); out.println("</taminterval>"); } if (config.getDateMinDate() != null) { printIndent(out, indent); out.print("<mindate>"); out.print(StringEscapeUtils.escapeXml(config.getDateMinDate())); out.println("</mindate>"); } if (config.getDateMaxDate() != null) { printIndent(out, indent); out.print("<maxdate>"); out.print(StringEscapeUtils.escapeXml(config.getDateMaxDate())); out.println("</maxdate>"); } } // Numeric domain specifics. else if (domain instanceof NumericDomain) { if (config.getNumericTamInterval() != null) { printIndent(out, indent); out.print("<taminterval>"); out.print(StringEscapeUtils.escapeXml(String.valueOf(config.getNumericTamInterval()))); out.println("</taminterval>"); } if (config.getNumericMinValue() != null) { printIndent(out, indent); out.print("<minvalue>"); out.print(StringEscapeUtils.escapeXml(String.valueOf(config.getNumericMinValue()))); out.println("</minvalue>"); } if (config.getNumericMaxValue() != null) { printIndent(out, indent); out.print("<maxvalue>"); out.print(StringEscapeUtils.escapeXml(String.valueOf(config.getNumericMaxValue()))); out.println("</maxvalue>"); } } }
From source file:org.openmrs.module.appointmentscheduling.web.controller.AppointmentBlockCalendarController.java
@RequestMapping(value = "/module/appointmentscheduling/appointmentBlockCalendar", method = RequestMethod.GET) public void showForm(HttpServletRequest request, ModelMap model) throws ParseException { if (Context.isAuthenticated()) { //Set the location from the session if (request.getSession().getAttribute("chosenLocation") != null) { Location location = (Location) request.getSession().getAttribute("chosenLocation"); model.addAttribute("chosenLocation", location); }//from ww w . j av a 2 s . c o m //Set the provider from the session if (request.getSession().getAttribute("chosenProvider") != null) { Provider provider = Context.getProviderService() .getProvider((Integer) request.getSession().getAttribute("chosenProvider")); model.addAttribute("chosenProvider", provider.getProviderId()); } //Set the appointmentType from the session if (request.getSession().getAttribute("chosenType") != null) { AppointmentType appointmentType = Context.getService(AppointmentService.class) .getAppointmentType((Integer) request.getSession().getAttribute("chosenType")); model.addAttribute("chosenType", appointmentType.getAppointmentTypeId()); } //Set the date interval from the session String fromDate; String toDate; Long fromDateAsLong; Long toDateAsLong; fromDate = (String) request.getSession().getAttribute("fromDate"); toDate = (String) request.getSession().getAttribute("toDate"); Calendar cal = Context.getDateTimeFormat().getCalendar(); if (fromDate == null && toDate == null) { //In case the user loaded the page for the first time, we will set to default the time interval (1 week from today). Date startDate = OpenmrsUtil.firstSecondOfDay(new Date()); fromDate = Context.getDateTimeFormat().format(startDate); fromDateAsLong = startDate.getTime(); cal.setTime(OpenmrsUtil.getLastMomentOfDay(new Date())); cal.add(Calendar.DAY_OF_MONTH, 6); Date endDate = cal.getTime(); toDate = Context.getDateTimeFormat().format(endDate); toDateAsLong = endDate.getTime(); } else { //Session is not empty and we need to change the locale if we have to. Locale lastLocale = (Locale) request.getSession().getAttribute("lastLocale"); Locale currentLocale = Context.getLocale(); Date startDate; Date endDate; //check if the last locale equals to the current locale if (lastLocale != null && lastLocale.toString().compareTo(currentLocale.toString()) != 0) { //if the locals are different startDate = OpenmrsUtil.getDateTimeFormat(lastLocale).parse(fromDate); endDate = OpenmrsUtil.getDateTimeFormat(lastLocale).parse(toDate); fromDate = Context.getDateTimeFormat().format(startDate); toDate = Context.getDateTimeFormat().format(endDate); fromDateAsLong = startDate.getTime(); toDateAsLong = endDate.getTime(); } else { startDate = OpenmrsUtil.getDateTimeFormat(currentLocale).parse(fromDate); endDate = OpenmrsUtil.getDateTimeFormat(currentLocale).parse(toDate); fromDateAsLong = startDate.getTime(); toDateAsLong = endDate.getTime(); } } //Update session variables - this will be updated in every locale change. HttpSession httpSession = request.getSession(); httpSession.setAttribute("fromDate", fromDate); httpSession.setAttribute("toDate", toDate); httpSession.setAttribute("lastLocale", Context.getLocale()); //Update model variables - what the page shows. model.addAttribute("fromDate", fromDateAsLong); model.addAttribute("toDate", toDateAsLong); } }
From source file:marytts.http.controllers.MaryController.java
/** * Method used to list available languages in the current MaryTTS instance * * @return a MaryListResponse object where result field contains the list of languages * @throws Exception in the case of the listing is failing *///w w w . j ava2s . c o m @RequestMapping("/listLanguages") public MaryListResponse listLanguages() throws Exception { HashSet<String> result = new HashSet<String>(); // List voices and only retrieve the names for (Locale l : localMary.getAvailableLocales()) { String[] elts = l.toString().split("_"); result.add(elts[0]); } return new MaryListResponse(new ArrayList<String>(result), null, false); }
From source file:com.github.cc007.headsinventory.locale.Translator.java
public Translator(String bundleName, Locale locale, ClassLoader classLoader) { this.locale = locale; this.bundleName = bundleName; this.classLoader = classLoader; ResourceBundle translations = null; ResourceBundle fallbackTranslations = null; try {//from www . j a v a2 s. c om InputStream translationsStream = getTranslationsFileStream( "locale/" + bundleName + "_" + locale.toString() + ".properties", classLoader); translations = new PropertyResourceBundle(translationsStream); InputStream fallbackTranslationsStream = getTranslationsFileStream( "locale/" + bundleName + ".properties", classLoader); fallbackTranslations = new PropertyResourceBundle(fallbackTranslationsStream); } catch (IOException ex) { HeadsInventory.getPlugin().getLogger().log(Level.SEVERE, null, ex); } this.translations = translations; this.fallbackTranslations = fallbackTranslations; }
From source file:com.sonicle.webtop.core.app.ServiceDescriptor.java
/** * Loads what's new file for specified service. * Contents will be taken and interpreted starting from desired version number. * @param serviceId Service ID//from ww w . ja v a2 s. c o m * @param locale Locale of contents (ex. it_IT) * @param fromVersion Starting version * @return HTML translated representation of loaded file. */ public String getWhatsnew(Locale locale, ServiceVersion fromVersion) { String resName = null; Whatsnew wn = null; synchronized (whatsnewCache) { try { String slocale = locale.toString(); if (whatsnewCache.containsKey(slocale)) { logger.trace("Getting whatsnew from cache [{}, {}]", manifest.getId(), slocale); wn = whatsnewCache.get(slocale); } else { resName = MessageFormat.format("/{0}/meta/whatsnew/{1}.txt", LangUtils.packageToPath(manifest.getId()), slocale); logger.debug("Loading whatsnew [{}, {}, ver. >= {}]", manifest.getId(), resName, fromVersion); wn = new Whatsnew(resName, defineWhatsnewVariables()); whatsnewCache.put(slocale, wn); } return wn.toHtml(fromVersion, manifest.getVersion()); } catch (ResourceNotFoundException ex) { logger.trace("Whatsnew file not available for service [{}]", manifest.getId()); } catch (IOException ex) { logger.trace(ex.getMessage()); } catch (Exception ex) { logger.error("Error getting whatsnew for service {}", manifest.getId(), ex); } return StringUtils.EMPTY; } }
From source file:marytts.http.controllers.MaryController.java
/** * Method used to list available regions for a given language in the current MaryTTS instance * * @param language the given language shortcut ("en", "de", ...) * @return a MaryListResponse object where result field contains the list of regions * @throws Exception in the case of the listing is failing *///www . j a va 2 s. com @RequestMapping("/listRegions") public MaryListResponse listRegions(@RequestParam(value = "language", defaultValue = "en") String language) throws Exception { HashSet<String> result = new HashSet<String>(); // List voices and only retrieve the names for (Locale l : localMary.getAvailableLocales()) { String[] elts = l.toString().split("_"); if (elts.length < 2) { if (elts[0].equals(language)) { result.add(language.toUpperCase()); } } else if (elts[0].equals(language)) { result.add(elts[1]); } } return new MaryListResponse(new ArrayList<String>(result), null, false); }
From source file:org.codelibs.fess.helper.SystemHelper.java
public List<Map<String, String>> getLanguageItems(final Locale locale) { try {/*from ww w. j a va2 s . c o m*/ final String localeStr = locale.toString(); return langItemsCache.get(localeStr); } catch (final ExecutionException e) { final List<Map<String, String>> langItems = new ArrayList<>(supportedLanguages.length); final String msg = ComponentUtil.getMessageManager().getMessage(locale, "labels.allLanguages"); final Map<String, String> defaultMap = new HashMap<>(2); defaultMap.put(Constants.ITEM_LABEL, msg); defaultMap.put(Constants.ITEM_VALUE, "all"); langItems.add(defaultMap); return langItems; } }