public String format(String key, String defaultValue, Object... args) { Locale locale = CurrentLocale.isSet() ? CurrentLocale.get() : Locale.getDefault(); Map<String, String> catalog = _catalogs.get(locale); String message = catalog.get(key); MessageFormat formatter = new MessageFormat(message, locale); return formatter.format(args, new StringBuffer(), null).toString(); }
public String format(String key, String dflt, Object... args) { if (key == null) { return dflt; } if (dflt == null) { dflt = key; } Locale locale = CurrentLocale.get(); // first look for most-specific catalog String message = getCatalogMessage(locale, key); if (message == null) { message = getCatalogMessage(new Locale(locale.getLanguage(), locale.getCountry()), key); } // now look for language if (message == null) { message = getCatalogMessage(new Locale(locale.getLanguage()), key); } // otherwise use the default catalog if (message == null) { message = getCatalogMessage(new Locale(""), key); } // and default to framework if (message == null) { message = getFrameworkMessage(locale, key); } if (message == null) { return dflt; } else { MessageFormat formater = new MessageFormat(message, locale); return formater.format(args, new StringBuffer(), null).toString(); } }