Java Resource Get getResourceBundleLocaleString(String sKey, Object[] sParam, String sResourceBundle)

Here you can find the source of getResourceBundleLocaleString(String sKey, Object[] sParam, String sResourceBundle)

Description

Returns the locale specific string for the given resource bundle key

License

Open Source License

Parameter

Parameter Description
sKey The given resource bundle key
sParam The params for the localized message
sResourceBundle The resource bundle to load <p>

Return

The required locale specific string if the key was found in the resource bundle, else it simply returns the key itself

Declaration

public static String getResourceBundleLocaleString(String sKey, Object[] sParam, String sResourceBundle) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**// w  w w .jav  a  2  s .c o m
     * Returns the locale specific string for the given
     * resource bundle key
     * <p>
     * @param sKey      The given resource bundle key
     * @param sParam   The params for the localized message
     * @param sResourceBundle   The resource bundle to load
     * <p>
     * @return   The required locale specific string if the
     *          key was found in the resource bundle, else
     *          it simply returns the key itself
     */
    public static String getResourceBundleLocaleString(String sKey, Object[] sParam, String sResourceBundle) {
        ResourceBundle resourcebundleWS = ResourceBundle.getBundle(sResourceBundle);

        try {
            String sString = resourcebundleWS.getString(sKey);
            return MessageFormat.format(sString, sParam);
        } catch (Throwable e) {
            return sKey;
        }
    }

    /**
     * Returns the locale specific string for the given
     * resource bundle key and given resource bundle
     * <p>
     * @param sKey            The given resource bundle key
     * @param sResourceBundle   The resource bundle to load
     * <p>
     * @return   The required locale specific string if the
     *          key was found in the resource bundle, else
     *          it simply returns the key itself
     */
    public static String getResourceBundleLocaleString(String sKey, String sResourceBundle) {
        ResourceBundle resourcebundleWS = ResourceBundle.getBundle(sResourceBundle);

        try {
            String sString = resourcebundleWS.getString(sKey);
            return sString;
        } catch (Throwable e) {
            return sKey;
        }
    }
}

Related

  1. getResourceAsStream(final Class caller, final String resource)
  2. getResourceAsStream(String resourceLocation)
  3. getResourceAsString(String prefix, String resource)
  4. getResourceAsString(String resource)
  5. getResourceBase()
  6. getResourceContent(Object object, String resource)
  7. getResourceDir(final Class testClass)
  8. getResourceExpression(String select)
  9. getResourceFile(Class clazz, String fileName)