Package com.pingidentity.sdk.locale
Class LanguagePackMessages
- java.lang.Object
-
- com.pingidentity.sdk.locale.LanguagePackMessages
-
public class LanguagePackMessages extends Object
Helper class used to retrieve localized messages. This class primarily wraps aResourceBundleand offers some convenience methods to use for PingFederate localization.The wrapped resource bundle is based on property files located in PingFederate's language-packs directory:
<pf-root>/server/default/conf/language-packs
PingFederate ships with a single language pack file used for English: pingfederate-messages.properties.Additional languages are supported by creating new language pack files with the same base name. For example, to add French support you would create a new property file named pingfederate-messages_fr.properties and add it to the language-packs directory. This new file would contain the same key/value pairs found in pingfederate-messages.properties except the values would be translated to French rather than English.
- Since:
- 6.11
- See Also:
ResourceBundle
-
-
Field Summary
Fields Modifier and Type Field Description static StringLANGUAGE_PACK_DIR_NAMEName of the directory used to store PingFederate language packs.
-
Constructor Summary
Constructors Constructor Description LanguagePackMessages(String resourceBundleBaseName, Locale locale)Construct an instance of LanguagePackMessages.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetMessage(String key)Retrieves a localized message for the key passed in.StringgetMessage(String keyPrefix, String key)Retrieves a localized message for the prefix and key passed in.StringgetMessage(String key, String[] substitutions)Retrieves a localized message for the key and substitutions passed in.StringgetMessage(String keyPrefix, String key, String... substitutions)Retrieves a localized message for the prefix, key, and substitutions passed in.StringgetMessageWithDefault(String key, String defaultMessage)Retrieves a localized message for the key prefix and key passed in.StringgetMessageWithDefault(String keyPrefix, String key, String defaultMessage)Retrieves a localized message for the key prefix and key passed in.StringgetMessageWithDefault(String key, String defaultMessage, String[] substitutions)Retrieves a localized message for the key prefix and key passed in.StringgetMessageWithDefault(String keyPrefix, String key, String defaultMessage, String[] substitutions)Retrieves a localized message for the key prefix and key passed in.ResourceBundlegetResourceBundle()Returns theResourceBundlebacking this class.
-
-
-
Field Detail
-
LANGUAGE_PACK_DIR_NAME
public static final String LANGUAGE_PACK_DIR_NAME
Name of the directory used to store PingFederate language packs.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LanguagePackMessages
public LanguagePackMessages(String resourceBundleBaseName, Locale locale)
Construct an instance of LanguagePackMessages. Behind the scenes we construct aResourceBundleusing the provided resource bundle base name. For example, "pingfederate-messages" is the base name for the resource bundle shipped with PingFederate.- Parameters:
resourceBundleBaseName- The base name for the resource bundle.locale- TheLocaleto use when retrieving localized messages.- See Also:
ResourceBundle,Locale
-
-
Method Detail
-
getMessage
public String getMessage(String key)
Retrieves a localized message for the key passed in. If the message is not found, the key is returned back.- Parameters:
key- Key used to search for localized message.- Returns:
- The localized message if found. Otherwise, the key passed in.
-
getMessage
public String getMessage(String keyPrefix, String key)
Retrieves a localized message for the prefix and key passed in. This method will first concatenate the prefix and key, then attempt to retrieve the message. If the message is not found, the concatenated key is returned back.- Parameters:
keyPrefix- The prefix used to prepend to the key.key- Key used to search for localized message.- Returns:
- The localized message if found. Otherwise, the concatenated key passed in.
-
getMessage
public String getMessage(String keyPrefix, String key, String... substitutions)
Retrieves a localized message for the prefix, key, and substitutions passed in. This method will first concatenate the prefix and key, then attempt to retrieve the message. Next, it will detect if the message contains any placeholder variables and replace them using substitutions. If the message is not found the concatenated key is returned back.
For example, given the following resource bundle key/value: oauth.approval.page.template.info.1={0} is requesting permission to do the following
Calling getMessage("oauth.approval.page.template.", "info.1", "Client A") would result in the localized message below:
Client A is requesting permission to do the following- Parameters:
keyPrefix- The prefix used to prepend to the key.key- Key used to search for localized message.substitutions- The array of substitutions to use in the message.- Returns:
- The localized message if found. Otherwise, the key passed in.
-
getMessage
public String getMessage(String key, String[] substitutions)
Retrieves a localized message for the key and substitutions passed in. If the message is not found, the key is returned back.- Parameters:
key- Key used to search for localized message.substitutions- The array of substitutions to use in the message.- Returns:
- The localized message if found. Otherwise, the key passed in.
-
getMessageWithDefault
public String getMessageWithDefault(String keyPrefix, String key, String defaultMessage)
Retrieves a localized message for the key prefix and key passed in. If the message is not found, then the default message will be returned.- Parameters:
keyPrefix- The prefix used to prepend to the key.key- Key used to search for localized message.defaultMessage- The default message to use if no localized string is found.- Returns:
- The localized message if found. Otherwise, the defaultMessage.
-
getMessageWithDefault
public String getMessageWithDefault(String key, String defaultMessage)
Retrieves a localized message for the key prefix and key passed in. If the a message is not found, then the default message will be returned.- Parameters:
key- Key used to search for localized message.defaultMessage- The default message to use if no localized string is found.- Returns:
- The localized message if found. Otherwise, the defaultMessage.
-
getMessageWithDefault
public String getMessageWithDefault(String keyPrefix, String key, String defaultMessage, String[] substitutions)
Retrieves a localized message for the key prefix and key passed in. If the a message is not found, then the default message will be returned.- Parameters:
keyPrefix- The prefix used to prepend to the key.key- Key used to search for localized message.defaultMessage- The default message to use if no localized string is found.substitutions- The array of substitutions to use in the message.- Returns:
- The localized message if found. Otherwise, the defaultMessage.
-
getMessageWithDefault
public String getMessageWithDefault(String key, String defaultMessage, String[] substitutions)
Retrieves a localized message for the key prefix and key passed in. If the a message is not found, then the default message will be returned.- Parameters:
key- Key used to search for localized message.defaultMessage- The default message to use if no localized string is found.substitutions- The array of substitutions to use in the message.- Returns:
- The localized message if found. Otherwise, the defaultMessage.
-
getResourceBundle
public ResourceBundle getResourceBundle()
Returns theResourceBundlebacking this class.- Returns:
- The
ResourceBundlebacking this class.
-
-