List of usage examples for java.util ResourceBundle getBundle
@CallerSensitive public static ResourceBundle getBundle(String baseName, Locale locale, ClassLoader loader)
From source file:net.refractions.udig.ui.internal.Messages.java
/** * Find the localized message for the given key. If arguments are given, then the * result message is formatted via {@link MessageFormat}. * * @param locale The locale to use to localize the given message. * @param key/*from w w w .jav a 2 s . c o m*/ * @param args If not null, then the message is formatted via {@link MessageFormat} * @return The message for the given key. */ public static String get(Locale locale, String key, Object... args) { try { // getBundle() caches the bundles ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale, Messages.class.getClassLoader()); if (args == null || args.length == 0) { return bundle.getString(key); } else { String msg = bundle.getString(key); return MessageFormat.format(msg, args); } } catch (Exception e) { return StringUtils.substringAfterLast(key, "_"); } }
From source file:com.grayfox.server.dao.jdbc.JdbcDao.java
protected String getQuery(String which) { return ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE_NAME, Locale.ROOT, new XmlResourceBundleControl()) .getString(which).trim();/*from w w w .ja v a 2 s .c om*/ }
From source file:Main.java
/** * Changes the locale of the messages./* www . j a v a2 s . c o m*/ * * @param locale * Locale the locale to change to. * @param resource * the name of the bundle resource */ static public ResourceBundle setLocale(final Locale locale, final String resource) { try { // BEGIN android-removed // final ClassLoader loader = VM.bootCallerClassLoader(); // END android-removed return (ResourceBundle) AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { // BEGIN android-changed return ResourceBundle.getBundle(resource, locale, ClassLoader.getSystemClassLoader()); // END android-changed } }); } catch (MissingResourceException e) { } return null; }
From source file:com.mgmtp.perfload.perfalyzer.util.ResourceBundleProvider.java
@Override public ResourceBundle get() { return ResourceBundle.getBundle("strings", locale, control); }
From source file:com.grayfox.server.dao.jdbc.JdbcDao.java
protected String getQuery(String which, Locale locale) { return SUPPORTED_LOCALES.contains(locale) ? ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE_NAME, locale, new XmlResourceBundleControl()) .getString(which).trim() : getQuery(which);// w w w . j a v a 2 s . co m }
From source file:com.evolveum.midpoint.web.util.Utf8BundleStringResourceLoader.java
@Override public String loadStringResource(Component component, String key, Locale locale, String style, String variation) {//from w ww .j ava 2s .c o m if (locale == null) { locale = Session.exists() ? Session.get().getLocale() : Locale.getDefault(); } ResourceBundle.Control control = new UTF8Control(); try { return ResourceBundle.getBundle(bundleName, locale, control).getString(key); } catch (MissingResourceException ex) { try { return ResourceBundle .getBundle(bundleName, locale, Thread.currentThread().getContextClassLoader(), control) .getString(key); } catch (MissingResourceException ex2) { return null; } } }
From source file:it.imtech.bookimporter.BookUtilityTest.java
/** * Test of getOrderedLanguages method, of class BookUtility. *//*w w w . j ava 2 s .c o m*/ public void testGetOrderedLanguages() { System.out.println("Test Ordering configuration languages: method -> getOrderedLanguages"); TreeMap<String, String> en = new TreeMap<String, String>(); en.put("English", "en"); en.put("German", "de"); en.put("Italian", "it"); TreeMap<String, String> it = new TreeMap<String, String>(); it.put("Inglese", "en"); it.put("Italiano", "it"); it.put("Tedesco", "de"); TreeMap<String, String> de = new TreeMap<String, String>(); de.put("Deutsch", "de"); de.put("English", "en"); de.put("Italienisch", "it"); try { CustomClassLoader loader = new CustomClassLoader(); Locale locale = new Locale("en"); ResourceBundle bundle = ResourceBundle.getBundle(RESOURCES, locale, loader); XMLConfiguration config = new XMLConfiguration(new File(DEBUG_XML)); TreeMap<String, String> result = BookUtility.getOrderedLanguages(config, bundle); assertEquals(en, result); locale = new Locale("it"); bundle = ResourceBundle.getBundle(RESOURCES, locale, loader); config = new XMLConfiguration(new File(DEBUG_XML)); result = BookUtility.getOrderedLanguages(config, bundle); assertEquals(it, result); locale = new Locale("de"); bundle = ResourceBundle.getBundle(RESOURCES, locale, loader); config = new XMLConfiguration(new File(DEBUG_XML)); result = BookUtility.getOrderedLanguages(config, bundle); assertEquals(de, result); } catch (ConfigurationException e) { fail("Ordering Language Test failed: ConfigurationException:- " + e.getMessage()); } }
From source file:StringManager.java
/** * Ctor specifying the package name. Attempt to load a resource bundle * from the package directory./*from w w w.j a v a2 s .c o m*/ * * @param packageName Name of package * @param classLoader Class loader to use */ StringManager(String packageName, ClassLoader loader) { super(); _bundleBaseName = packageName + ".I18NStrings"; _rsrcBundle = ResourceBundle.getBundle(_bundleBaseName, Locale.getDefault(), loader); if (loader instanceof URLClassLoader) { _bundleLoaderUrLs = ((URLClassLoader) loader).getURLs(); } }
From source file:de.highbyte_le.weberknecht.i18n.LocaleMatcher.java
/** * @return the resourceBundle/* w w w .ja va2 s . c om*/ */ public synchronized ResourceBundle findResourceBundle() { if (null == resourceBundle) { if (locales.size() > 0) { Locale firstLocale = locales.get(0); this.resourceBundle = ResourceBundle.getBundle(bundleName, firstLocale, new ResourceBundleControl()); } if (null == resourceBundle || "".equals(this.resourceBundle.getLocale().toString())) this.resourceBundle = ResourceBundle.getBundle(bundleName, defaultLocale, new ResourceBundleControl()); } return resourceBundle; }
From source file:com.safetys.framework.jmesa.core.message.ResourceBundleMessages.java
private ResourceBundle getResourceBundle(String messagesLocation) throws MissingResourceException { return ResourceBundle.getBundle(messagesLocation, locale, getClass().getClassLoader()); }