/** * Get the named bundle. * <p/> * You can override the getLocale() methodName to change the behaviour of how * to choose locale for the bundles that are returned. Typically you would * use the TextProvider interface to get the users configured locale, or use * your own methodName to allow the user to select the locale and store it in * the session (by using the SessionAware interface). * * @param aBundleName bundle name * @return a resource bundle */ public ResourceBundle getTexts(String aBundleName) { return LocalizedTextUtil.findResourceBundle(aBundleName, getLocale()); }
public ResourceBundle getTexts(String bundleName) { return LocalizedTextUtil.findResourceBundle(bundleName, ActionContext.getContext().getLocale()); }
/** * Returns a localized message for the specified key, aTextName. Neither the key nor the * message is evaluated. * * @param aTextName the message key * @param locale the locale the message should be for * @return a localized 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) { List<String> localList = classLoaderMap.get(Thread.currentThread().getContextClassLoader().hashCode()); for (String bundleName : localList) { ResourceBundle bundle = findResourceBundle(bundleName, locale); if (bundle != null) { reloadBundles(); try { return bundle.getString(aTextName); } catch (MissingResourceException e) { // will be logged when not found in any bundle } } } if (devMode) { LOG.warn("Missing key [#0] in bundles [#1]!", aTextName, localList); } else if (LOG.isDebugEnabled()) { LOG.debug("Missing key [#0] in bundles [#1]!", aTextName, localList); } return null; }
/** * 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; } }