Java Code Examples for java.text.MessageFormat#setLocale()

The following examples show how to use java.text.MessageFormat#setLocale() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OverwriteDesign.java    From ldparteditor with MIT License 6 votes vote down vote up
/**
 * Create contents of the dialog.
 *
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite cmp_Container = (Composite) super.createDialogArea(parent);
    GridLayout gridLayout = (GridLayout) cmp_Container.getLayout();
    gridLayout.verticalSpacing = 10;
    gridLayout.horizontalSpacing = 10;

    Label lbl_overwrite = new Label(cmp_Container, SWT.NONE);

    Object[] messageArguments = {whichFile};
    MessageFormat formatter = new MessageFormat(""); //$NON-NLS-1$
    formatter.setLocale(MyLanguage.LOCALE);
    formatter.applyPattern(I18n.DIALOG_Replace);
    lbl_overwrite.setText(formatter.format(messageArguments));

    return cmp_Container;
}
 
Example 2
Source File: CpmLocalizedMessage.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the localized message.
 *
 * @param aResourceBundleName the a resource bundle name
 * @param aMessageKey the a message key
 * @param aArguments the a arguments
 * @return the localized message
 */
public static String getLocalizedMessage(String aResourceBundleName, String aMessageKey,
        Object[] aArguments) {
  if (aMessageKey == null)
    return null;

  try {
    // locate the resource bundle for this exception's messages
    ResourceBundle bundle = ResourceBundle.getBundle(aResourceBundleName, Locale.getDefault());
    // retrieve the message from the resource bundle
    String message = bundle.getString(aMessageKey);
    // if arguments exist, use MessageFormat to include them
    if (aArguments != null && aArguments.length > 0) {
      MessageFormat fmt = new MessageFormat(message);
      fmt.setLocale(Locale.getDefault());
      return fmt.format(aArguments);
    } else
      return message;
  } catch (Exception e) {
    return "EXCEPTION MESSAGE LOCALIZATION FAILED: " + e.toString();
  }

}
 
Example 3
Source File: EntityPropertiesServiceSimple.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public String getPropertyMessage(String code, Object[] args, Locale locale) {
    if (code == null) {
        throw new IllegalArgumentException("code (key) cannot be null when looking up messages");
    }
    String message = null;
    String template = bundle.getString(code);
    if (template != null) {
        if (args != null && args.length > 0) {
            MessageFormat formatter = new MessageFormat("");
            if (locale == null) {
                locale = Locale.getDefault();
            }
            formatter.setLocale(locale);
            formatter.applyPattern(template);
            message = formatter.format(args);
        } else {
            message = template;
        }
    }
    return message;
}
 
Example 4
Source File: LocalizedMessage.java    From ripple-lib-java with ISC License 6 votes vote down vote up
protected String formatWithTimeZone(
        String template,
        Object[] arguments, 
        Locale locale,
        TimeZone timezone) 
{
    MessageFormat mf = new MessageFormat(" ");
    mf.setLocale(locale);
    mf.applyPattern(template);
    if (!timezone.equals(TimeZone.getDefault())) 
    {
        Format[] formats = mf.getFormats();
        for (int i = 0; i < formats.length; i++) 
        {
            if (formats[i] instanceof DateFormat) 
            {
                DateFormat temp = (DateFormat) formats[i];
                temp.setTimeZone(timezone);
                mf.setFormat(i,temp);
            }
        }
    }
    return mf.format(arguments);
}
 
Example 5
Source File: LocalizedMessage.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
protected String formatWithTimeZone(
        String template,
        Object[] arguments, 
        Locale locale,
        TimeZone timezone) 
{
    MessageFormat mf = new MessageFormat(" ");
    mf.setLocale(locale);
    mf.applyPattern(template);
    if (!timezone.equals(TimeZone.getDefault())) 
    {
        Format[] formats = mf.getFormats();
        for (int i = 0; i < formats.length; i++) 
        {
            if (formats[i] instanceof DateFormat) 
            {
                DateFormat temp = (DateFormat) formats[i];
                temp.setTimeZone(timezone);
                mf.setFormat(i,temp);
            }
        }
    }
    return mf.format(arguments);
}
 
Example 6
Source File: DatFile.java    From ldparteditor with MIT License 5 votes vote down vote up
private boolean checkFileCollision(File theFile) {
    if (theFile.lastModified() > lastModified) {
        MessageBox messageBox = new MessageBox(Editor3DWindow.getWindow().getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.CANCEL | SWT.NO);
        messageBox.setText(I18n.DIALOG_ModifiedTitle);

        Object[] messageArguments = {getShortName(), getLastSavedOpened()};
        MessageFormat formatter = new MessageFormat(""); //$NON-NLS-1$
        formatter.setLocale(MyLanguage.LOCALE);
        formatter.applyPattern(I18n.DIALOG_Modified);
        messageBox.setMessage(formatter.format(messageArguments));

        int result2 = messageBox.open();
        if (result2 == SWT.CANCEL) {
            return true;
        } else if (result2 == SWT.YES) {
            Project.removeUnsavedFile(this);
            parseForData(true);
            Editor3DWindow.getWindow().updateTree_unsavedEntries();
            HashSet<EditorTextWindow> windows = new HashSet<EditorTextWindow>(Project.getOpenTextWindows());
            for (EditorTextWindow win : windows) {
                win.updateTabWithDatfile(this);
            }
            return true;
        }
    }
    return false;
}
 
Example 7
Source File: StringManager.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
/**
 * Get a string from the underlying resource bundle and format
 * it with the given set of arguments.
 *
 * @param key
 * @param args
 */
public String getString(final String key, final Object... args) {
    String value = getString(key);
    if (value == null) {
        value = key;
    }

    MessageFormat mf = new MessageFormat(value);
    mf.setLocale(locale);
    return mf.format(args, new StringBuffer(), null).toString();
}
 
Example 8
Source File: StringManager.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Get a string from the underlying resource bundle and format
 * it with the given set of arguments.
 *
 * @param key  The key for the required message
 * @param args The values to insert into the message
 *
 * @return The request string formatted with the provided arguments or the
 *         key if the key was not found.
 */
public String getString(final String key, final Object... args) {
    String value = getString(key);
    if (value == null) {
        value = key;
    }

    MessageFormat mf = new MessageFormat(value);
    mf.setLocale(locale);
    return mf.format(args, new StringBuffer(), null).toString();
}
 
Example 9
Source File: ExtendedMessageFormatTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Replace MessageFormat(String, Locale) constructor (not available until JDK 1.4).
 * @param pattern string
 * @param locale Locale
 * @return MessageFormat
 */
private MessageFormat createMessageFormat(final String pattern, final Locale locale) {
    final MessageFormat result = new MessageFormat(pattern);
    if (locale != null) {
        result.setLocale(locale);
        result.applyPattern(pattern);
    }
    return result;
}
 
Example 10
Source File: JREvaluator.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 
 */
private MessageFormat getMessageFormat(String pattern)
{
	MessageFormat messageFormat = new MessageFormat("");
	messageFormat.setLocale((Locale)locale.getValue());
	messageFormat.applyPattern(pattern);
	return messageFormat;
}
 
Example 11
Source File: ExtendedMessageFormatTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Replace MessageFormat(String, Locale) constructor (not available until JDK 1.4).
 * @param pattern string
 * @param locale Locale
 * @return MessageFormat
 */
private MessageFormat createMessageFormat(String pattern, Locale locale) {
    MessageFormat result = new MessageFormat(pattern);
    if (locale != null) {
        result.setLocale(locale);
        result.applyPattern(pattern);
    }
    return result;
}
 
Example 12
Source File: StringManager.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Get a string from the underlying resource bundle and format
 * it with the given set of arguments.
 *
 * @param key
 * @param args
 */
public String getString(final String key, final Object... args) {
    String value = getString(key);
    if (value == null) {
        value = key;
    }

    MessageFormat mf = new MessageFormat(value);
    mf.setLocale(locale);
    return mf.format(args, new StringBuffer(), null).toString();
}
 
Example 13
Source File: StringManager.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Get a string from the underlying resource bundle and format
 * it with the given set of arguments.
 *
 * @param key
 * @param args
 */
public String getString(final String key, final Object... args) {
    String value = getString(key);
    if (value == null) {
        value = key;
    }

    MessageFormat mf = new MessageFormat(value);
    mf.setLocale(locale);
    return mf.format(args, new StringBuffer(), null).toString();
}
 
Example 14
Source File: StringManager.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Get a string from the underlying resource bundle and format
 * it with the given set of arguments.
 *
 * @param key  The key for the required message
 * @param args The values to insert into the message
 *
 * @return The requested string formatted with the provided arguments
 */
public String getString(final String key, final Object... args) {
    String value = getString(key);
    if (value == null) {
        value = key;
    }

    MessageFormat mf = new MessageFormat(value);
    mf.setLocale(locale);
    return mf.format(args, new StringBuffer(), null).toString();
}
 
Example 15
Source File: StringManager.java    From mmall20180107 with Apache License 2.0 5 votes vote down vote up
/**
 * Get a string from the underlying resource bundle and format
 * it with the given set of arguments.
 *
 * @param key
 * @param args
 */
public String getString(final String key, final Object... args) {
	String value = getString(key);
	if (value == null) {
		value = key;
	}

	MessageFormat mf = new MessageFormat(value);
	mf.setLocale(locale);
	return mf.format(args, new StringBuffer(), null).toString();
}
 
Example 16
Source File: QuickStylesPanel.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void updatePanelContentModel(CommandPanelContentModel model,
        ResourceBundle resourceBundle, Locale locale) {
    MessageFormat mf = new MessageFormat(resourceBundle.getString("PanelStyles.text"));
    mf.setLocale(locale);

    List<CommandGroup> commandGroups = model.getCommandGroups();
    for (int groupIndex = 0; groupIndex < commandGroups.size(); groupIndex++) {
        CommandGroup commandGroup = commandGroups.get(groupIndex);
        String commandGroupName = mf.format(new Object[] { groupIndex });
        commandGroup.setTitle(commandGroupName);
    }
}
 
Example 17
Source File: StringManager.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
/**
 * Get a string from the underlying resource bundle and format
 * it with the given set of arguments.
 *
 * @param key
 * @param args
 */
public String getString(final String key, final Object... args) {
  String value = getString(key);
  if (value == null) {
    value = key;
  }

  MessageFormat mf = new MessageFormat(value);
  mf.setLocale(this.locale);
  return mf.format(args, new StringBuffer(), null).toString();
}
 
Example 18
Source File: StringManager.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Get a string from the underlying resource bundle and format
 * it with the given set of arguments.
 *
 * @param key  The key for the required message
 * @param args The values to insert into the message
 *
 * @return The request string formatted with the provided arguments or the
 *         key if the key was not found.
 */
public String getString(final String key, final Object... args) {
    String value = getString(key);
    if (value == null) {
        value = key;
    }

    MessageFormat mf = new MessageFormat(value);
    mf.setLocale(locale);
    return mf.format(args, new StringBuffer(), null).toString();
}
 
Example 19
Source File: ExtendedMessageFormatTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Replace MessageFormat(String, Locale) constructor (not available until JDK 1.4).
 * @param pattern string
 * @param locale Locale
 * @return MessageFormat
 */
private MessageFormat createMessageFormat(String pattern, Locale locale) {
    MessageFormat result = new MessageFormat(pattern);
    if (locale != null) {
        result.setLocale(locale);
        result.applyPattern(pattern);
    }
    return result;
}
 
Example 20
Source File: TextUtil.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static MessageFormat getFormatter(Locale locale) {
MessageFormat formatter = new MessageFormat("");
formatter.setLocale(locale);
return formatter;
   }