/** * Returns a localized message for the specified key, aTextName, substituting variables from the * array of params into the message. Neither the key nor the message is evaluated. * * @param aTextName the message key * @param locale the locale the message should be for * @param params an array of objects to be substituted into the message text * @return A formatted message based on the specified key, or null if no localized message can be found for it */ public static String findDefaultText(String aTextName, Locale locale, Object[] params) { String defaultText = findDefaultText(aTextName, locale); if (defaultText != null) { MessageFormat mf = buildMessageFormat(defaultText, locale); return formatWithNullDetection(mf, params); } return null; }
/** * Gets the default message. */ private static GetDefaultMessageReturnArg getDefaultMessage(String key, Locale locale, ValueStack valueStack, Object[] args, String defaultMessage) { GetDefaultMessageReturnArg result = null; boolean found = true; if (key != null) { String message = findDefaultText(key, locale); if (message == null) { message = defaultMessage; found = false; // not found in bundles } // defaultMessage may be null if (message != null) { MessageFormat mf = buildMessageFormat(TextParseUtil.translateVariables(message, valueStack), locale); String msg = formatWithNullDetection(mf, args); result = new GetDefaultMessageReturnArg(msg, found); } } return result; }
/** * Gets the message from the named resource bundle. */ private static String getMessage(String bundleName, Locale locale, String key, ValueStack valueStack, Object[] args) { ResourceBundle bundle = findResourceBundle(bundleName, locale); if (bundle == null) { return null; } reloadBundles(valueStack.getContext()); try { String message = TextParseUtil.translateVariables(bundle.getString(key), valueStack); MessageFormat mf = buildMessageFormat(message, locale); return formatWithNullDetection(mf, args); } catch (MissingResourceException e) { if (devMode) { LOG.warn("Missing key [#0] in bundle [#1]!", key, bundleName); } else if (LOG.isDebugEnabled()) { LOG.debug("Missing key [#0] in bundle [#1]!", key, bundleName); } return null; } }
MessageFormat mf = buildMessageFormat(message, locale);