Java Resource Message getMessageString(String key, Locale locale)

Here you can find the source of getMessageString(String key, Locale locale)

Description

Gets messages

License

Apache License

Parameter

Parameter Description
key a parameter

Declaration

public static String getMessageString(String key, Locale locale) 

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 {
    private final static String BUNDLE_NAME = "org.cloudfoundry.autoscaler.nls.ServerMessages";

    /**/*ww w . ja  v  a 2  s  .  c o m*/
     * Gets messages
     * 
     * @param key
     * @return
     */
    public static String getMessageString(String key) {
        return getMessageString(key, new Object[] {});
    }

    /**
     * Get messages
     * 
     * @param key
     * @param params
     * @return
     */
    public static String getMessageString(String key, Object... params) {
        ResourceBundle NONLS_MESSAGE_RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
        if (params == null || params.length == 0)
            return NONLS_MESSAGE_RESOURCE_BUNDLE.getString(key);
        else
            return MessageFormat.format(NONLS_MESSAGE_RESOURCE_BUNDLE.getString(key), params);
    }

    /**
     * Gets messages
     * 
     * @param key
     * @return
     */
    public static String getMessageString(String key, Locale locale) {
        return getMessageString(key, locale, new Object[] {});
    }

    /**
     * Get messages
     * 
     * @param key
     * @param locale
     * @param params
     * @return
     */
    public static String getMessageString(String key, Locale locale, Object... params) {
        ResourceBundle MESSAGE_RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, locale); //$NLS$
        if (params == null || params.length == 0)
            return MESSAGE_RESOURCE_BUNDLE.getString(key);
        else
            return MessageFormat.format(MESSAGE_RESOURCE_BUNDLE.getString(key), params);

    }
}

Related

  1. getMessageFormat(final String bundleKey, final String messageKey, final Locale locale)
  2. getMessageFormattedTime(Date date)
  3. getMessageNoKey(String messageName)
  4. getMessages(final Class cls)
  5. getMessageString(String bundleName, String key, Object[] params, Locale locale)
  6. getMessageString(String key, Locale locale)
  7. getMessageWithArgs(String pTemplate, Object pArg0)