Package org.apache.struts2.text

# Interface LocalizedTextProvider

All Superinterfaces:
  `Serializable`

All Known Implementing Classes:
  `GlobalLocalizedTextProvider`, `StrutsLocalizedTextProvider`

public interface LocalizedTextProvider extends Serializable

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addDefaultResourceBundle(String bundleName)`
  Adds the bundle to the internal list of default bundles.
  `String`
  `findDefaultText(String textKey, Locale locale)`
  Returns a localized message for the specified key, aTextName.
  `String`
  `findDefaultText(String textKey, Locale locale, Object[] params)`
  Returns a localized message for the specified key, aTextName, substituting variables from the array of params into the message.
  `ResourceBundle`
  `findResourceBundle(String bundleName, Locale locale)`
  Finds the given resource bundle by it's name.
  `String`
  `findText(Class<?> startClazz, String textKey, Locale locale)`
  Calls `findText(Class startClazz, String textKey, Locale locale, String defaultMessage, Object[] args)` with textKey as the default message.
  `String`
  `findText(Class<?> startClazz, String textKey, Locale locale, String defaultMessage, Object[] args)`
  Finds a localized text message for the given key, textKey.
  `String`
  `findText(Class<?> startClazz, String textKey, Locale locale, String defaultMessage, Object[] args, ValueStack valueStack)`
  Finds a localized text message for the given key, textKey.
  `String`
  `findText(ResourceBundle bundle, String textKey, Locale locale)`
  Finds a localized text message for the given key, aTextName, in the specified resource bundle with aTextName as the default message.
  `String`
  `findText(ResourceBundle bundle, String textKey, Locale locale, String defaultMessage, Object[] args)`
  Finds a localized text message for the given key, aTextName, in the specified resource bundle.
  `String`
  `findText(ResourceBundle bundle, String textKey, Locale locale, String defaultMessage, Object[] args, ValueStack valueStack)`
  Finds a localized text message for the given key, aTextName, in the specified resource bundle.

- ## Method Details

  - ### findDefaultText

    String findDefaultText(String textKey, Locale locale)
    Returns a localized message for the specified key, aTextName. Neither the key nor the message is evaluated.
    Parameters:
      `textKey` - the message key
      `locale` - the locale the message should be for
    Returns:
      a localized message based on the specified key, or null if no localized message can be found for it

  - ### findDefaultText

    String findDefaultText(String textKey, Locale locale, Object[] params)
    Returns a localized message for the specified key, aTextName, substituting variables from the array of params into the message. Neither the key nor the message is evaluated.
    Parameters:
      `textKey` - the message key
      `locale` - the locale the message should be for
      `params` - an array of objects to be substituted into the message text
    Returns:
      A formatted message based on the specified key, or null if no localized message can be found for it

  - ### findResourceBundle

    ResourceBundle findResourceBundle(String bundleName, Locale locale)
    Finds the given resource bundle by it's name.

    Will use `Thread.currentThread().getContextClassLoader()` as the classloader.

    Parameters:
      `bundleName` - the name of the bundle (usually it's FQN classname).
      `locale` - the locale.
    Returns:
      the bundle, `null` if not found.

  - ### findText

    String findText(Class<?> startClazz, String textKey, Locale locale)
    Calls `findText(Class startClazz, String textKey, Locale locale, String defaultMessage, Object[] args)` with textKey as the default message.
    Parameters:
      `startClazz` - class name
      `textKey` - text name
      `locale` - the locale
    Returns:
      the localized text, or null if none can be found and no defaultMessage is provided
    See Also:
      - `findText(Class startClazz, String textKey, Locale locale, String defaultMessage, Object[] args)`

  - ### findText

    String findText(Class<?> startClazz, String textKey, Locale locale, String defaultMessage, Object[] args)
    Finds a localized text message for the given key, textKey. Both the key and the message itself is evaluated as required. The following algorithm is used to find the requested message:
    1. Look for the message in the default resource bundles.
    2. If not found, return defaultMessage

    When looking for the message, if the key indexes a collection (e.g. user.phone[0]) and a message for that specific key cannot be found, the general form will also be looked up (i.e. user.phone[*]).

    If a message is found, it will also be interpolated. Anything within `${...}` will be treated as an OGNL expression and evaluated as such.

    Parameters:
      `startClazz` - the class whose name to use as the start point for the search
      `textKey` - the key to find the text message for
      `locale` - the locale the message should be for
      `defaultMessage` - the message to be returned if no text message can be found in any resource bundle
      `args` - arguments resource bundle
    Returns:
      the localized text, or null if none can be found and no defaultMessage is provided

  - ### findText

    String findText(Class<?> startClazz, String textKey, Locale locale, String defaultMessage, Object[] args, ValueStack valueStack)
    Finds a localized text message for the given key, textKey. Both the key and the message itself is evaluated as required. The following algorithm is used to find the requested message:
    1. Look for the message in the default resource bundles.
    2. If not found, return defaultMessage

    When looking for the message, if the key indexes a collection (e.g. user.phone[0]) and a message for that specific key cannot be found, the general form will also be looked up (i.e. user.phone[*]).

    If a message is found, it will also be interpolated. Anything within `${...}` will be treated as an OGNL expression and evaluated as such.

    If a message is not found a DEBUG level log warning will be logged.

    Parameters:
      `startClazz` - the class whose name to use as the start point for the search
      `textKey` - the key to find the text message for
      `locale` - the locale the message should be for
      `defaultMessage` - the message to be returned if no text message can be found in any resource bundle
      `args` - arguments
      `valueStack` - the value stack to use to evaluate expressions instead of the one in the ActionContext ThreadLocal
    Returns:
      the localized text, or null if none can be found and no defaultMessage is provided

  - ### findText

    String findText(ResourceBundle bundle, String textKey, Locale locale)
    Finds a localized text message for the given key, aTextName, in the specified resource bundle with aTextName as the default message.

    If a message is found, it will also be interpolated. Anything within `${...}` will be treated as an OGNL expression and evaluated as such.

    Parameters:
      `bundle` - a resource bundle name
      `textKey` - text name
      `locale` - the locale
    Returns:
      the localized text, or null if none can be found and no defaultMessage is provided
    See Also:
      - `findText(ResourceBundle, String, Locale, String, Object[])`

  - ### findText

    String findText(ResourceBundle bundle, String textKey, Locale locale, String defaultMessage, Object[] args)
    Finds a localized text message for the given key, aTextName, in the specified resource bundle.

    If a message is found, it will also be interpolated. Anything within `${...}` will be treated as an OGNL expression and evaluated as such.

    If a message is not found a WARN log will be logged.

    Parameters:
      `bundle` - the bundle
      `textKey` - the key
      `locale` - the locale
      `defaultMessage` - the default message to use if no message was found in the bundle
      `args` - arguments for the message formatter.
    Returns:
      the localized text, or null if none can be found and no defaultMessage is provided

  - ### findText

    String findText(ResourceBundle bundle, String textKey, Locale locale, String defaultMessage, Object[] args, ValueStack valueStack)
    Finds a localized text message for the given key, aTextName, in the specified resource bundle.

    If a message is found, it will also be interpolated. Anything within `${...}` will be treated as an OGNL expression and evaluated as such.

    If a message is not found a WARN log will be logged.

    Parameters:
      `bundle` - the bundle
      `textKey` - the key
      `locale` - the locale
      `defaultMessage` - the default message to use if no message was found in the bundle
      `args` - arguments for the message formatter.
      `valueStack` - the OGNL value stack.
    Returns:
      the localized text, or null if none can be found and no defaultMessage is provided

  - ### addDefaultResourceBundle

    void addDefaultResourceBundle(String bundleName)
    Adds the bundle to the internal list of default bundles. If the bundle already exists in the list it will be re-added.
    Parameters:
      `bundleName` - the name of the bundle to add.