Interface SimpleLocalizationService

All Known Subinterfaces:
LocalizationService
All Known Implementing Classes:
DefaultLocalizationService, SimpleLocalizationServiceImpl

public interface SimpleLocalizationService

Provides localization functionality using the interface provided by ResourceBundle, plus leverages a "search path" style traversal of the ResourceBundle objects named by the locale.default.bundles to discover a value for a given key.

It is suggested that one handle dealing with concatenated messages using MessageFormat and properties files.

Version:
$Id: LocalizationService.java 535465 2007-05-05 06:58:06Z tv $
Author:
Jon S. Stevens, Daniel Rall, Leonard Richardson, Stephen McConnell, Thomas Vandahl
  • Field Details

    • ROLE

      static final String ROLE
    • SERVICE_NAME

      static final String SERVICE_NAME
  • Method Details

    • getDefaultLanguage

      String getDefaultLanguage()
      Retrieves the default language (as specified in the config file).
      Returns:
      the default language
    • getDefaultCountry

      String getDefaultCountry()
      Retrieves the default country (as specified in the config file).
      Returns:
      the default country
    • getDefaultLocale

      Locale getDefaultLocale()
      Retrieves the default Locale (as created from default language and default country).
      Returns:
      the default locale
    • getDefaultBundleName

      String getDefaultBundleName()
      Retrieves the name of the default bundle (as specified in the config file), or the first in the list if there are more than one.
      Returns:
      the default bundle name
    • getBundleNames

      String[] getBundleNames()
      Retrieves the list of names of bundles to search by default for ResourceBundle keys (as specified in the config file).
      Returns:
      The list of configured bundle names.
    • getBundle

      ResourceBundle getBundle()
      Convenience method to get the default ResourceBundle.
      Returns:
      A localized ResourceBundle.
    • getBundle

      ResourceBundle getBundle(String bundleName)
      Returns a ResourceBundle given the bundle name and the default locale information supplied by the configuration.
      Parameters:
      bundleName - Name of bundle.
      Returns:
      A localized ResourceBundle.
    • getBundle

      ResourceBundle getBundle(String bundleName, Locale locale)
      Convenience method to get a ResourceBundle based on name and Locale.
      Parameters:
      bundleName - Name of bundle.
      locale - A Locale.
      Returns:
      A localized ResourceBundle.
    • getString

      String getString(String bundleName, Locale locale, String key) throws MissingResourceException
      Tries very hard to return a value, looking first in the specified bundle, then searching list of default bundles (giving precedence to earlier bundles over later bundles).
      Parameters:
      bundleName - Name of the bundle to look in first.
      locale - Locale to get text for.
      key - Name of the text to retrieve.
      Returns:
      Localized text.
      Throws:
      MissingResourceException - if the resource is not found
    • getString

      String getString(String key)
      Returns the value for the key in the default bundle and the default locale.
      Parameters:
      key - The key to retrieve the value for.
      Returns:
      The value mapped to the key.
    • setBundle

      void setBundle(String defaultBundle)
      This method sets the name of the defaultBundle.
      Parameters:
      defaultBundle - Name of default bundle.
    • format

      String format(String bundleName, Locale locale, String key, Object arg1)
      Formats a localized value using the provided object.
      Parameters:
      bundleName - The bundle in which to look for the localizable text.
      locale - The locale for which to format the text.
      key - The identifier for the localized text to retrieve,
      arg1 - The object to use as {0} when formatting the localized text.
      Returns:
      Formatted localized text.
      See Also:
    • format

      String format(String bundleName, Locale locale, String key, Object arg1, Object arg2)
      Formats a localized value using the provided objects.
      Parameters:
      bundleName - The bundle in which to look for the localizable text.
      locale - The locale for which to format the text.
      key - The identifier for the localized text to retrieve,
      arg1 - The object to use as {0} when formatting the localized text.
      arg2 - The object to use as {1} when formatting the localized text.
      Returns:
      Formatted localized text.
      See Also:
    • format

      String format(String bundleName, Locale locale, String key, Object[] args)
      Formats a localized value using the provided objects.
      Parameters:
      bundleName - The bundle in which to look for the localizable text.
      locale - The locale for which to format the text.
      key - The identifier for the localized text to retrieve,
      args - The objects to use as {0}, {1}, etc. when formatting the localized text.
      Returns:
      Formatted localized text.