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.api.nls.APIServerMessages";
    private final static ResourceBundle NONLS_MESSAGE_RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);

    /**//ww  w.j a  va  2 s  . c  om
     * Gets messages
     * 
     * @param key
     * @return
     */
    public static String getMessageString(String key) {
        return NONLS_MESSAGE_RESOURCE_BUNDLE.getString(key);
    }

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

    /**
     * Gets messages
     * 
     * @param key
     * @return
     */
    public static String getMessageString(String key, Locale locale) {
        ResourceBundle MESSAGE_RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, locale); //$NON-NLS-1$
        return MESSAGE_RESOURCE_BUNDLE.getString(key);
    }

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

Related

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