Here you can find the source of getMessage(final String bundleName, final Locale locale, final String key, final Object... params)
Parameter | Description |
---|---|
bundleName | The bundle name |
locale | The locale of the message |
key | The message key |
params | Message parameters (optional) |
public static String getMessage(final String bundleName, final Locale locale, final String key, final Object... params)
//package com.java2s; //License from project: Open Source License import java.text.MessageFormat; import java.util.Locale; import java.util.ResourceBundle; public class Main { /**/* w w w . j a v a 2 s .co m*/ * Get a message from a resource bundle present in classpath. * * @param bundleName * The bundle name * @param locale * The locale of the message * @param key * The message key * @param params * Message parameters (optional) * @return The formatted message */ public static String getMessage(final String bundleName, final Locale locale, final String key, final Object... params) { final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); final ResourceBundle bundle = ResourceBundle.getBundle(bundleName, locale, classLoader); String text = bundle.getString(key); if (params != null) { final MessageFormat mf = new MessageFormat(text, locale); text = mf.format(params, new StringBuffer(), null).toString(); } return text; } }