Search in sources :

Example 71 with ResourceBundle

use of java.util.ResourceBundle in project intellij-community by JetBrains.

the class YAMLBundle method getBundle.

private static ResourceBundle getBundle() {
    ResourceBundle bundle = SoftReference.dereference(ourBundle);
    if (bundle == null) {
        bundle = ResourceBundle.getBundle(BUNDLE);
        ourBundle = new SoftReference<>(bundle);
    }
    return bundle;
}
Also used : ResourceBundle(java.util.ResourceBundle)

Example 72 with ResourceBundle

use of java.util.ResourceBundle in project zm-mailbox by Zimbra.

the class L10nUtil method getBundleKeySet.

/**
     * Gets the list of keys for a given bundle for a given locale
     * @param basename The name of the bundle (ex ZMsgs)
     * @param lc The locale, null will use the default system locale
     * @return A set of keys if any found, will not return null
     */
public static Set<String> getBundleKeySet(String basename, Locale lc) {
    ResourceBundle rb;
    try {
        if (lc == null) {
            lc = Locale.getDefault();
        }
        rb = ResourceBundle.getBundle(basename, lc, sMsgClassLoader);
        Set<String> result = new HashSet<String>();
        Enumeration<String> keysEnum = rb.getKeys();
        while (keysEnum.hasMoreElements()) {
            result.add(keysEnum.nextElement());
        }
        return result;
    } catch (MissingResourceException e) {
        // just return an empty set if we can't find the bundle
        return Collections.emptySet();
    }
}
Also used : MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle) HashSet(java.util.HashSet)

Example 73 with ResourceBundle

use of java.util.ResourceBundle in project zm-mailbox by Zimbra.

the class L10nUtil method getMessage.

public static String getMessage(String basename, String key, Locale lc, Object... args) {
    ResourceBundle rb;
    try {
        if (lc == null) {
            lc = Locale.getDefault();
        }
        rb = ResourceBundle.getBundle(basename, lc, sMsgClassLoader);
        String fmt = rb.getString(key);
        if (fmt != null && args != null && args.length > 0) {
            return MessageFormat.format(fmt, args);
        } else {
            return fmt;
        }
    } catch (MissingResourceException e) {
        ZimbraLog.misc.warn("no resource bundle for base name " + basename + " can be found, " + "(locale=" + key + ")", e);
        return null;
    }
}
Also used : MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle)

Example 74 with ResourceBundle

use of java.util.ResourceBundle in project voltdb by VoltDB.

the class BundleHandler method getString.

/**
     * Retrieves, from the <code>ResourceBundle</code> object corresponding
     * to the specified handle, the <code>String</code> value corresponding
     * to the specified key.  <code>null</code> is retrieved if either there
     *  is no <code>ResourceBundle</code> object for the handle or there is no
     * <code>String</code> value for the specified key. <p>
     *
     * @param handle an <code>int</code> handle to a
     *      <code>ResourceBundle</code> object
     * @param key A <code>String</code> key to a <code>String</code> value
     * @return The String value correspoding to the specified handle and key.
     */
public static String getString(int handle, String key) {
    ResourceBundle bundle;
    String s;
    synchronized (mutex) {
        if (handle < 0 || handle >= bundleList.size() || key == null) {
            bundle = null;
        } else {
            bundle = (ResourceBundle) bundleList.get(handle);
        }
    }
    if (bundle == null) {
        s = null;
    } else {
        try {
            s = bundle.getString(key);
        } catch (Exception e) {
            s = null;
        }
    }
    return s;
}
Also used : ResourceBundle(java.util.ResourceBundle) MissingResourceException(java.util.MissingResourceException)

Example 75 with ResourceBundle

use of java.util.ResourceBundle in project tdi-studio-se by Talend.

the class ComponentsFactory method getComponentResourceBundle.

private ResourceBundle getComponentResourceBundle(IComponent currentComp, String source, String cachedPathSource, AbstractComponentsProvider provider) {
    try {
        AbstractComponentsProvider currentProvider = provider;
        if (currentProvider == null) {
            ComponentsProviderManager componentsProviderManager = ComponentsProviderManager.getInstance();
            Collection<AbstractComponentsProvider> providers = componentsProviderManager.getProviders();
            for (AbstractComponentsProvider curProvider : providers) {
                String path = new Path(curProvider.getInstallationFolder().toString()).toPortableString();
                if (source.startsWith(path)) {
                    // fix for TDI-19889 and TDI-20507 to get the correct component provider
                    if (cachedPathSource != null) {
                        if (path.contains(cachedPathSource)) {
                            currentProvider = curProvider;
                            break;
                        }
                    } else {
                        currentProvider = curProvider;
                        break;
                    }
                }
            }
        }
        String installPath = currentProvider.getInstallationFolder().toString();
        String label = ComponentFilesNaming.getInstance().getBundleName(currentComp.getName(), installPath.substring(installPath.lastIndexOf(IComponentsFactory.COMPONENTS_INNER_FOLDER)));
        if (currentProvider.isUseLocalProvider()) {
            // if the component use local provider as storage (for user / ecosystem components)
            // then get the bundle resource from the current main component provider.
            // note: code here to review later, service like this shouldn't be used...
            ResourceBundle bundle = null;
            IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
            if (brandingService.isPoweredOnlyCamel()) {
                bundle = currentProvider.getResourceBundle(label);
            } else {
                ITisLocalProviderService service = (ITisLocalProviderService) GlobalServiceRegister.getDefault().getService(ITisLocalProviderService.class);
                bundle = service.getResourceBundle(label);
            }
            return bundle;
        } else {
            ResourceBundle bundle = ResourceBundle.getBundle(label, Locale.getDefault(), new ResClassLoader(currentProvider.getClass().getClassLoader()));
            return bundle;
        }
    } catch (IOException e) {
        ExceptionHandler.process(e);
    }
    return null;
}
Also used : AbstractComponentsProvider(org.talend.core.model.components.AbstractComponentsProvider) Path(org.eclipse.core.runtime.Path) ComponentBundleToPath(org.talend.designer.core.model.components.ComponentBundleToPath) ResClassLoader(org.talend.designer.core.ITisLocalProviderService.ResClassLoader) ITisLocalProviderService(org.talend.designer.core.ITisLocalProviderService) ResourceBundle(java.util.ResourceBundle) IBrandingService(org.talend.core.ui.branding.IBrandingService) IOException(java.io.IOException)

Aggregations

ResourceBundle (java.util.ResourceBundle)1189 Locale (java.util.Locale)180 MissingResourceException (java.util.MissingResourceException)150 Test (org.junit.Test)100 ArrayList (java.util.ArrayList)71 HashMap (java.util.HashMap)70 IOException (java.io.IOException)67 PropertyResourceBundle (java.util.PropertyResourceBundle)56 URL (java.net.URL)48 File (java.io.File)47 Map (java.util.Map)45 InputStream (java.io.InputStream)43 Enumeration (java.util.Enumeration)34 HashSet (java.util.HashSet)30 Test (org.junit.jupiter.api.Test)30 ActionMessage (org.apache.struts.action.ActionMessage)29 MessageFormat (java.text.MessageFormat)28 ListResourceBundle (java.util.ListResourceBundle)28 Set (java.util.Set)26 Preferences (java.util.prefs.Preferences)21