Here you can find the source of formatString(ResourceBundle resourceBundle, String key, Object data)
Parameter | Description |
---|---|
resourceBundle | A resource bundle. |
key | A resource key. |
data | An object. |
public static String formatString(ResourceBundle resourceBundle, String key, Object data)
//package com.java2s; // are made available under the terms of the Eclipse Public License v1.0 import java.text.MessageFormat; import java.util.MissingResourceException; import java.util.ResourceBundle; public class Main { /**/*from www. j av a 2s .co m*/ * Returns the localized string associated with a resource key and formatted * with a given string. * * @param resourceBundle * A resource bundle. * @param key * A resource key. * @param data * An object. * @return A formatted localized string. */ public static String formatString(ResourceBundle resourceBundle, String key, Object data) { if (resourceBundle != null) { try { String localizedStr = resourceBundle.getString(key); return MessageFormat.format(localizedStr, new Object[] { data }); } catch (MissingResourceException e) { } } return '[' + key + ']'; } /** * Returns the localized string associated with a resource key and formatted * with two given string. * * @param resourceBundle * A resource bundle. * @param key * A resource key. * @param data1 * An object. * @param data2 * An object. * @return A formatted localized string. */ public static String formatString(ResourceBundle resourceBundle, String key, Object data1, Object data2) { if (resourceBundle != null) { try { String localizedStr = resourceBundle.getString(key); return MessageFormat.format(localizedStr, new Object[] { data1, data2 }); } catch (MissingResourceException e) { } } return '[' + key + ']'; } /** * Returns the localized string associated with a resource key and formatted * with a given string. * * @param resourceBundle * A resource bundle. * @param key * A resource key. * @param data * An array of objects. * @return A formatted localized string. */ public static String formatString(ResourceBundle resourceBundle, String key, Object[] data) { if (resourceBundle != null) { try { String localizedStr = resourceBundle.getString(key); return MessageFormat.format(localizedStr, data); } catch (MissingResourceException e) { } } return '[' + key + ']'; } /** * Returns the localized string associated with a resource key. * * @param resourceBundle * A resource bundle. * @param key * A resource key. * @return A localized string. */ public static String getString(ResourceBundle resourceBundle, String key) { if (resourceBundle != null) { try { return resourceBundle.getString(key); } catch (MissingResourceException e) { } } return '[' + key + ']'; } }