Java Locale Format format(Locale locale, ResourceBundle bundle, String key, Object... args)

Here you can find the source of format(Locale locale, ResourceBundle bundle, String key, Object... args)

Description

Formats a message from the specified ResourceBundle using the specified arguments.

License

Apache License

Parameter

Parameter Description
locale the Locale (see MessageFormat#setLocale(Locale) )
bundle the ResourceBundle containing the message pattern
key the key of the message pattern in the ResourceBundle
args the arguments needed for formatting the message

Return

the formatted message

Declaration

public static String format(Locale locale, ResourceBundle bundle, String key, Object... args) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.MessageFormat;
import java.util.Locale;
import java.util.ResourceBundle;

public class Main {
    /**/* w  w w.  j a va  2 s .  co  m*/
     * Formats a message from the specified {@link ResourceBundle} using the specified arguments.
     * <p>
     * @param locale the {@link Locale} (see {@link MessageFormat#setLocale(Locale)})
     * @param bundle the {@link ResourceBundle} containing the message pattern
     * @param key the key of the message pattern in the {@link ResourceBundle}
     * @param args the arguments needed for formatting the message
     * @return the formatted message
     */
    public static String format(Locale locale, ResourceBundle bundle, String key, Object... args) {
        MessageFormat formatter = new MessageFormat("");
        formatter.setLocale(locale);
        formatter.applyPattern(bundle.getString(key));
        return formatter.format(args);
    }
}

Related

  1. format(final Date date, final String format)
  2. format(final Date date, final String format)
  3. format(final double num, final int prec)
  4. format(final String bundleKey, final String messageKey, final Locale locale, final Object... arguments)
  5. format(int[] a)
  6. format(Locale locale, String key, Object... arguments)
  7. format(Number number)
  8. format(Number number, Locale locale)
  9. format(Object input, int style)