Interface LocalizedTextProvider
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
GlobalLocalizedTextProvider
,StrutsLocalizedTextProvider
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addDefaultResourceBundle
(String bundleName) Adds the bundle to the internal list of default bundles.findDefaultText
(String textKey, Locale locale) Returns a localized message for the specified key, aTextName.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.findResourceBundle
(String bundleName, Locale locale) Finds the given resource bundle by it's name.CallsfindText(Class startClazz, String textKey, Locale locale, String defaultMessage, Object[] args)
with textKey as the default message.Finds a localized text message for the given key, textKey.findText
(Class<?> startClazz, String textKey, Locale locale, String defaultMessage, Object[] args, ValueStack valueStack) Finds a localized text message for the given key, textKey.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.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.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
Returns a localized message for the specified key, aTextName. Neither the key nor the message is evaluated.- Parameters:
textKey
- the message keylocale
- 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
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 keylocale
- the locale the message should be forparams
- 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
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
CallsfindText(Class startClazz, String textKey, Locale locale, String defaultMessage, Object[] args)
with textKey as the default message.- Parameters:
startClazz
- class nametextKey
- text namelocale
- the locale- Returns:
- the localized text, or null if none can be found and no defaultMessage is provided
- See Also:
-
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:- Look for the message in the default resource bundles.
- 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 searchtextKey
- the key to find the text message forlocale
- the locale the message should be fordefaultMessage
- the message to be returned if no text message can be found in any resource bundleargs
- 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:- Look for the message in the default resource bundles.
- 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 searchtextKey
- the key to find the text message forlocale
- the locale the message should be fordefaultMessage
- the message to be returned if no text message can be found in any resource bundleargs
- argumentsvalueStack
- 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
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 nametextKey
- text namelocale
- the locale- Returns:
- the localized text, or null if none can be found and no defaultMessage is provided
- See Also:
-
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 bundletextKey
- the keylocale
- the localedefaultMessage
- the default message to use if no message was found in the bundleargs
- 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 bundletextKey
- the keylocale
- the localedefaultMessage
- the default message to use if no message was found in the bundleargs
- 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
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.
-