/** * Retrieve a resource bundle of the default or fail-over locale. * * @param packageName The package to search in * @return The resource bundle * @throws MissingResourceException in case both resource bundles couldn't be found. */ public static ResourceBundle getBundle( String packageName ) throws MissingResourceException { return GlobalMessageUtil.getBundle( packageName, PKG ); }
public static ResourceBundle getBundle() { if ( RESOURCE_BUNDLE == null ) { RESOURCE_BUNDLE = GlobalMessageUtil.getBundle( BUNDLE_NAME, Messages.class ); } return RESOURCE_BUNDLE; }
public static ResourceBundle getBundle( Locale locale, String packagePath, Class<?> resourceClass ) { return getBundle( locale, packagePath, resourceClass, true ); }
/** * Returns a {@link ResourceBundle} for the given {@link Locale} and {@code packagePath}, using the {@link * GlobalMessages} class loader. * * @param locale the {@link Locale} for which the {@link ResourceBundle} is being retrieved * @param packagePath the full path to the localized message file without the {@code .properties} extension * @return a {@link ResourceBundle} for the given {@link Locale} and {@code packagePath}, using the {@link * GlobalMessages} class loader * @throws MissingResourceException when the {@link ResourceBundle} cannot be found */ @VisibleForTesting static ResourceBundle getBundle( final Locale locale, final String packagePath ) throws MissingResourceException { return GlobalMessageUtil.getBundle( locale, packagePath, PKG ); }
public static String getStringFromBundle( final String bundleName, final String key, final Object... params ) { ResourceBundle bundle = null; try { bundle = GlobalMessageUtil.getBundle( bundleName, ValidatorMessages.class ); } catch ( MissingResourceException e ) { return "??? missing resource ???"; } catch ( NullPointerException e ) { return "??? baseName null ???"; } String unformattedString = null; try { unformattedString = bundle.getString( key ); } catch ( Exception e ) { return "??? " + key + " ???"; } String formattedString = MessageFormat.format( unformattedString, params ); return formattedString; }
@VisibleForTesting static String calculateString( final String packageName, final Locale locale, final String key, final Object[] parameters, final Class<?> resourceClass, final String bundleName, final boolean fallbackOnRoot ) throws MissingResourceException { try { ResourceBundle bundle = getBundle( locale, packageName + "." + bundleName, resourceClass, fallbackOnRoot ); String unformattedString = bundle.getString( key ); String string = MessageFormat.format( unformattedString, parameters ); return string; } catch ( IllegalArgumentException e ) { final StringBuilder msg = new StringBuilder(); msg.append( "Format problem with key=[" ).append( key ).append( "], locale=[" ).append( locale ).append( "], package=" ).append( packageName ).append( " : " ).append( e.toString() ); log.error( msg.toString() ); log.error( Const.getStackTracker( e ) ); throw new MissingResourceException( msg.toString(), packageName, key ); } }
/** * Retrieve a resource bundle of the default or fail-over locales. * * @param packagePath The package to search in * @param resourceClass the class to use to resolve the bundle * @return The resource bundle * @throws MissingResourceException in case both resource bundles couldn't be found. */ public static ResourceBundle getBundle( final String packagePath, final Class<?> resourceClass ) throws MissingResourceException { final Set<Locale> activeLocales = getActiveLocales(); for ( final Locale locale : activeLocales ) { try { return getBundle( locale, packagePath, resourceClass ); } catch ( MissingResourceException e ) { final StringBuilder msg = new StringBuilder(); msg.append( "Unable to find properties file for package '" ).append( packagePath ).append( "' and class '" ) .append( resourceClass.getName() ).append( "' in the available locales: " ).append( locale ); // nothing to do, an exception will be thrown if no bundle is found log.warn( msg.toString() ); } } final StringBuilder msg = new StringBuilder(); msg.append( "Unable to find properties file for package '" ).append( packagePath ).append( "' and class '" ) .append( resourceClass.getName() ).append( "' in the available locales: " ).append( Arrays.asList( activeLocales ) ); throw new MissingResourceException( msg.toString(), resourceClass.getName(), packagePath ); }
if ( overlay.getResourceBundleUri() != null ) { try { res = GlobalMessageUtil.getBundle( overlay.getResourceBundleUri(), SpoonPerspectiveManager.class ); } catch ( MissingResourceException ignored ) { res = GlobalMessageUtil.getBundle( overlay.getOverlayUri().replace( ".xul", ".properties" ), SpoonPerspectiveManager.class ); } catch ( MissingResourceException ignored ) {