Package org.forgerock.util.i18n
Class LocalizableString
- java.lang.Object
-
- org.forgerock.util.i18n.LocalizableString
-
public class LocalizableString extends Object
Represents a String which could be localizable. If it is localizable it needs to be in the following format,i18n:bundle#keywhich is a URI where:i18n:is the scheme specifying that the string is localizablebundleis the path of the bundle in the classpath (optional, if missing, aClasshas to be provided and will be used as resource bundle name)key, the fragment, is the key of the translated string
ClassLoaderin which the resource bundle can be found, in the assumption that when it comes to serializing this object, the calling code (e.g. HttpFrameworkServlet and the Grizzly HandlerAdapter) is in a different classloader and so will not have direct access to the resource bundle.A default value
LocalizableStringcan be provided so that if the key is not found in the bundle, another value can be specified, which could be either another bundle reference, or a plain value.
-
-
Field Summary
Fields Modifier and Type Field Description static StringTRANSLATION_KEY_PREFIXA constant used to indicate a string should be translated.
-
Constructor Summary
Constructors Constructor Description LocalizableString(String value)String only constructor for non-localizableStringvalues.LocalizableString(String value, Class<?> type)Constructor for potentially localizableString.LocalizableString(String value, ClassLoader loader)Constructor for potentially localizableString.LocalizableString(String key, ClassLoader loader, LocalizableString defaultValue)Constructor for potentially localizableString.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)The default equals operation.inthashCode()Default hashcode implementation.StringtoString()The default toString method.StringtoTranslatedString(PreferredLocales locales)Returns the contained string, translated if applicable.
-
-
-
Field Detail
-
TRANSLATION_KEY_PREFIX
public static final String TRANSLATION_KEY_PREFIX
A constant used to indicate a string should be translated.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LocalizableString
public LocalizableString(String value)
String only constructor for non-localizableStringvalues.- Parameters:
value- a string
-
LocalizableString
public LocalizableString(String value, Class<?> type)
Constructor for potentially localizableString. If resource bundle name not provided in thevalue, then the providedtypename will be used instead.- Parameters:
value- the String (i18n:#key.name is accepted here)type- class used to support relative resource bundle lookup (must not benull)
-
LocalizableString
public LocalizableString(String value, ClassLoader loader)
Constructor for potentially localizableString.- Parameters:
value- the Stringloader- theClassLoaderwhere the string definition should be obtained
-
LocalizableString
public LocalizableString(String key, ClassLoader loader, LocalizableString defaultValue)
Constructor for potentially localizableString. If a default value is not specified, if thekeyis a valid URI, its fragment will be used, and otherwise the wholekeyvalue will be used.- Parameters:
key- the localizable keyloader- theClassLoaderwhere the string definition should be obtaineddefaultValue- the default value to use if not localizable.
-
-
Method Detail
-
toTranslatedString
public String toTranslatedString(PreferredLocales locales)
Returns the contained string, translated if applicable.- Parameters:
locales- The preferred locales for the translation.- Returns:
- the translated string
-
toString
public String toString()
The default toString method. No translation is applied.
-
equals
public boolean equals(Object o)
The default equals operation.
-
-