/** * Gets the requested localized message. * <p/> * <p> * The current Request and Response are used to help determine the messages * resource to use. * <ol> * <li>Exact locale match, return the registered locale message * <li>Language match, but not a locale match, return the registered * language message * <li>Return supplied default message * </ol> * <p> * The message can be formatted with optional arguments using the * {@link java.text.MessageFormat} syntax. * </p> * * @param key * @param defaultMessage * @param args * @return the message or the key if the key does not exist */ public String getWithDefault(String key, String defaultMessage, String language, Object... args) { String value = get(key, language, args); if (value.equals(key)) { // key does not exist, format default message value = formatMessage(defaultMessage, language, args); } return value; }
String value = messages.getProperty(key); if (value != null) { return formatMessage(value, language, args); } else { log.warn("Failed to find '{}' in Messages", key);