List of usage examples for java.text MessageFormat setLocale
public void setLocale(Locale locale)
From source file:de.kaiserpfalzEdv.commons.HandleI18NImpl.java
@Override public String get(final String key, final Object[] parameters) { MessageFormat message = new MessageFormat(get(key)); message.setLocale(locale); LOG.debug("Translating {}='{}' with parameters: {} ...", key, get(key), parameters); return message.format(parameters); }
From source file:net.fenyo.gnetwatch.Config.java
/** * Returns an i18n message./* w w w. j a v a 2 s. c o m*/ * @param key i18n key. * @param params array of arguments to scatter in the i18n locale dependant message. * @return String locale dependant message. */ public String getPattern(final String key, final Object[] params) { final MessageFormat formatter = new MessageFormat(""); formatter.setLocale(locale); formatter.applyPattern(getString(key)); return formatter.format(params); }
From source file:org.web4thejob.print.CsvPrinter.java
@Override public File print(String title, List<RenderScheme> renderSchemes, Query query, List<Entity> entities) { Assert.notNull(renderSchemes);/* ww w.j a v a 2 s . co m*/ int i = 0; File file; try { String crlf = System.getProperty("line.separator"); file = createTempFile(); BufferedWriter writer = createFileStream(file); writer.write(title + crlf); writer.newLine(); CSVWriter csv = new CSVWriter(writer); for (Entity entity : entities) { if (entity == null) { Assert.notNull(query); entity = ContextUtil.getDRS().findUniqueByQuery(query); } if (query != null && query.hasMasterCriterion()) { writer.write(describeMasterCriteria(query)); writer.newLine(); } if (query != null) { writer.write(describeCriteria(query)); writer.newLine(); } writeLine(csv, ContextUtil.getBean(ConversionService.class), entity, renderSchemes.get(i)); writer.newLine(); writer.newLine(); i++; } //timestamp List<String> line = new ArrayList<String>(); line.add(L10nMessages.L10N_LABEL_TIMESTAMP.toString()); MessageFormat df = new MessageFormat(""); df.setLocale(CoreUtil.getUserLocale()); df.applyPattern("{0,date,yyyy-MM-dd hh:mm:ss}"); line.add(df.format(new Object[] { new Date() })); csv.writeNext(line.toArray(new String[line.size()])); writer.newLine(); writer.write("powered by web4thejob.org"); writer.close(); } catch (IOException e) { throw new RuntimeException(e); } return file; }
From source file:org.web4thejob.print.CsvPrinter.java
@Override public File print(String title, RenderScheme renderScheme, Query query, List<Entity> entities) { Assert.notNull(renderScheme);//from w w w . java2 s. c om Assert.isTrue(renderScheme.getSchemeType() == SchemeType.LIST_SCHEME); if (entities == null) { Assert.notNull(query); entities = ContextUtil.getDRS().findByQuery(query); } File file; try { String crlf = System.getProperty("line.separator"); file = createTempFile(); BufferedWriter writer = createFileStream(file); writer.write(title + crlf); writer.newLine(); if (query != null && query.hasMasterCriterion()) { writer.write(describeMasterCriteria(query)); writer.newLine(); } if (query != null) { writer.write(describeCriteria(query)); writer.newLine(); } CSVWriter csv = new CSVWriter(writer); List<String> header = new ArrayList<String>(); for (RenderElement item : renderScheme.getElements()) { if (item.getPropertyPath().getLastStep().isBlobType()) continue; header.add(item.getFriendlyName()); } csv.writeNext(header.toArray(new String[header.size()])); ConversionService conversionService = ContextUtil.getBean(ConversionService.class); for (final Entity entity : entities) { writeLine(csv, conversionService, entity, renderScheme); } writer.newLine(); //timestamp List<String> line = new ArrayList<String>(); line.add(L10nMessages.L10N_LABEL_TIMESTAMP.toString()); MessageFormat df = new MessageFormat(""); df.setLocale(CoreUtil.getUserLocale()); df.applyPattern("{0,date,yyyy-MM-dd hh:mm:ss}"); line.add(df.format(new Object[] { new Date() })); csv.writeNext(line.toArray(new String[line.size()])); writer.newLine(); writer.write("powered by web4thejob.org"); writer.close(); } catch (IOException e) { throw new RuntimeException(e); } return file; }
From source file:net.jcreate.e3.table.message.AbstractMessageSource.java
/** * Create a MessageFormat for the given message and Locale. * <p>This implementation creates an empty MessageFormat first, * populating it with Locale and pattern afterwards, to stay * compatible with J2SE 1.3.//www . java 2 s . c om * @param msg the message to create a MessageFormat for * @param locale the Locale to create a MessageFormat for * @return the MessageFormat instance */ protected MessageFormat createMessageFormat(String msg, Locale locale) { if (logger.isDebugEnabled()) { logger.debug("Creating MessageFormat for pattern [" + msg + "] and locale '" + locale + "'"); } MessageFormat messageFormat = new MessageFormat(""); messageFormat.setLocale(locale); if (msg != null) { messageFormat.applyPattern(msg); } return messageFormat; }
From source file:org.pentaho.reporting.libraries.base.util.ResourceBundleSupport.java
/** * Formats the message stored in the resource bundle (using a MessageFormat). * * @param key the resourcebundle key * @param parameters the parameter collection for the message * @return the formated string//from w w w . j a va 2 s.c o m */ public String formatMessage(final String key, final Object[] parameters) { final MessageFormat format = new MessageFormat(strictString(key)); format.setLocale(getLocale()); return format.format(parameters); }
From source file:json_to_xml_1.java
private String getI10nStringFormatted(String i10nStringName, Object... arguments) { MessageFormat formatter = new MessageFormat(""); formatter.setLocale(this.getLocale()); formatter.applyPattern(getI10nString(i10nStringName)); return formatter.format(arguments); }
From source file:org.apache.struts.util.MessageResources.java
/** * Returns a text message after parametric replacement of the specified * parameter placeholders. A null string result will be returned by this * method if no resource bundle has been configured. * * @param locale The requested message Locale, or <code>null</code> for * the system default Locale * @param key The message key to look up * @param args An array of replacement parameters for placeholders *//* w w w.j a va2s . co m*/ public String getMessage(Locale locale, String key, Object[] args) { // Cache MessageFormat instances as they are accessed if (locale == null) { locale = defaultLocale; } MessageFormat format = null; String formatKey = messageKey(locale, key); synchronized (formats) { format = (MessageFormat) formats.get(formatKey); if (format == null) { String formatString = getMessage(locale, key); if (formatString == null) { return returnNull ? null : ("???" + formatKey + "???"); } format = new MessageFormat(escape(formatString)); format.setLocale(locale); formats.put(formatKey, format); } } return format.format(args); }
From source file:com.npower.dm.util.MessageResources.java
/** * Returns a text message after parametric replacement of the specified * parameter placeholders. A null string result will be returned by * this method if no resource bundle has been configured. * * @param locale The requested message Locale, or <code>null</code> * for the system default Locale// w w w . ja v a 2 s .c o m * @param key The message key to look up * @param args An array of replacement parameters for placeholders */ public String getMessage(Locale locale, String key, Object args[]) { // Cache MessageFormat instances as they are accessed if (locale == null) { locale = defaultLocale; } MessageFormat format = null; String formatKey = messageKey(locale, key); synchronized (formats) { format = (MessageFormat) formats.get(formatKey); if (format == null) { String formatString = getMessage(locale, key); if (formatString == null) { return returnNull ? null : ("???" + formatKey + "???"); } format = new MessageFormat(escape(formatString)); format.setLocale(locale); formats.put(formatKey, format); } } return format.format(args); }
From source file:com.opensymphony.xwork2.util.DefaultLocalizedTextProvider.java
private MessageFormat buildMessageFormat(String pattern, Locale locale) { MessageFormatKey key = new MessageFormatKey(pattern, locale); MessageFormat format = messageFormats.get(key); if (format == null) { format = new MessageFormat(pattern); format.setLocale(locale); format.applyPattern(pattern);//from w w w .j a v a2s . co m messageFormats.put(key, format); } return format; }