use of java.util.ListResourceBundle in project commons by twitter.
the class JULBridgeHandlerTest method checkMessageWithResourceBundleIsFormatted.
@Test
public void checkMessageWithResourceBundleIsFormatted() {
ResourceBundle bundle = new ListResourceBundle() {
@Override
protected Object[][] getContents() {
return new Object[][] { { "test is successful", "le test fonctionne" } };
}
};
LogRecord record = new LogRecord(Level.FINEST, "test is successful");
record.setResourceBundle(bundle);
assertThat(JULBridgeHandler.formatMessage(record), is("le test fonctionne"));
}
use of java.util.ListResourceBundle in project j2objc by google.
the class Messages method loadResourceBundle.
/**
* Return a named ResourceBundle for a particular locale. This method mimics the behavior
* of ResourceBundle.getBundle().
*
* @param className the name of the class that implements ListResourceBundle,
* without language suffix.
* @return the ResourceBundle
* @throws MissingResourceException
* @xsl.usage internal
*/
private ListResourceBundle loadResourceBundle(String resourceBundle) throws MissingResourceException {
m_resourceBundleName = resourceBundle;
Locale locale = getLocale();
ListResourceBundle lrb;
try {
ResourceBundle rb = ResourceBundle.getBundle(m_resourceBundleName, locale);
lrb = (ListResourceBundle) rb;
} catch (MissingResourceException e) {
try // try to fall back to en_US if we can't load
{
// Since we can't find the localized property file,
// fall back to en_US.
lrb = (ListResourceBundle) ResourceBundle.getBundle(m_resourceBundleName, new Locale("en", "US"));
} catch (MissingResourceException e2) {
// very bad, definitely very bad...not going to get very far
throw new MissingResourceException("Could not load any resource bundles." + m_resourceBundleName, m_resourceBundleName, "");
}
}
m_resourceBundle = lrb;
return lrb;
}
use of java.util.ListResourceBundle in project j2objc by google.
the class ListResourceBundleTest method test_handleGetObjectLjava_lang_String.
@SuppressWarnings("unchecked")
public void test_handleGetObjectLjava_lang_String() {
ListResourceBundle bundle;
String name = "tests.support.Support_TestResource";
Locale.setDefault(new Locale("en", "US"));
bundle = (ListResourceBundle) ResourceBundle.getBundle(name, new Locale("fr", "FR", "VAR"));
Enumeration keys = bundle.getKeys();
String keyValue = null;
Vector result = new Vector();
while (keys.hasMoreElements()) {
result.addElement(bundle.handleGetObject((String) keys.nextElement()));
}
assertEquals(9, result.size());
assertTrue(result.contains(null));
assertTrue(result.contains("frFRVARValue4"));
assertTrue(result.contains("frFRVARChildValue1"));
assertTrue(result.contains("frFRVARChildValue2"));
assertTrue(result.contains("frFRVARChildValue3"));
assertTrue(result.remove(null));
assertTrue(result.remove(null));
assertTrue(result.remove(null));
}
use of java.util.ListResourceBundle in project robovm by robovm.
the class ListResourceBundleTest method test_handleGetObjectLjava_lang_String.
public void test_handleGetObjectLjava_lang_String() {
ListResourceBundle bundle;
String name = "tests.support.Support_TestResource";
Locale.setDefault(new Locale("en", "US"));
bundle = (ListResourceBundle) ResourceBundle.getBundle(name, new Locale("fr", "FR", "VAR"));
Enumeration keys = bundle.getKeys();
String keyValue = null;
Vector result = new Vector();
while (keys.hasMoreElements()) {
result.addElement(bundle.handleGetObject((String) keys.nextElement()));
}
assertEquals(9, result.size());
assertTrue(result.contains(null));
assertTrue(result.contains("frFRVARValue4"));
assertTrue(result.contains("frFRVARChildValue1"));
assertTrue(result.contains("frFRVARChildValue2"));
assertTrue(result.contains("frFRVARChildValue3"));
assertTrue(result.remove(null));
assertTrue(result.remove(null));
assertTrue(result.remove(null));
}
use of java.util.ListResourceBundle in project robovm by robovm.
the class Messages method loadResourceBundle.
/**
* Return a named ResourceBundle for a particular locale. This method mimics the behavior
* of ResourceBundle.getBundle().
*
* @param className the name of the class that implements ListResourceBundle,
* without language suffix.
* @return the ResourceBundle
* @throws MissingResourceException
* @xsl.usage internal
*/
private ListResourceBundle loadResourceBundle(String resourceBundle) throws MissingResourceException {
m_resourceBundleName = resourceBundle;
Locale locale = getLocale();
ListResourceBundle lrb;
try {
ResourceBundle rb = ResourceBundle.getBundle(m_resourceBundleName, locale);
lrb = (ListResourceBundle) rb;
} catch (MissingResourceException e) {
try // try to fall back to en_US if we can't load
{
// Since we can't find the localized property file,
// fall back to en_US.
lrb = (ListResourceBundle) ResourceBundle.getBundle(m_resourceBundleName, new Locale("en", "US"));
} catch (MissingResourceException e2) {
// very bad, definitely very bad...not going to get very far
throw new MissingResourceException("Could not load any resource bundles." + m_resourceBundleName, m_resourceBundleName, "");
}
}
m_resourceBundle = lrb;
return lrb;
}
Aggregations