public class LocalizableString extends Object
i18n:bundle#key
which is a URI where:
i18n:
is the scheme specifying that the string is localizablebundle
is the path of the bundle in the classpath (optional, if missing,
a Class
has to be provided and will be used as resource bundle name)key
, the fragment, is the key of the translated stringClassLoader
in 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 LocalizableString
can 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.
Modifier and Type | Field and Description |
---|---|
static String |
TRANSLATION_KEY_PREFIX
A constant used to indicate a string should be translated.
|
Constructor and Description |
---|
LocalizableString(String value)
String only constructor for non-localizable
String values. |
LocalizableString(String value,
Class<?> type)
Constructor for potentially localizable
String . |
LocalizableString(String value,
ClassLoader loader)
Constructor for potentially localizable
String . |
LocalizableString(String key,
ClassLoader loader,
LocalizableString defaultValue)
Constructor for potentially localizable
String . |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o)
The default equals operation.
|
int |
hashCode()
Default hashcode implementation.
|
String |
toString()
The default toString method.
|
String |
toTranslatedString(PreferredLocales locales)
Returns the contained string, translated if applicable.
|
public static final String TRANSLATION_KEY_PREFIX
public LocalizableString(String value)
String
values.value
- a stringpublic LocalizableString(String value, Class<?> type)
String
.
If resource bundle name not provided in the value
, then the provided type
name will be
used instead.value
- the String (i18n:#key.name is accepted here)type
- class used to support relative resource bundle lookup (must not be null
)public LocalizableString(String value, ClassLoader loader)
String
.value
- the Stringloader
- the ClassLoader
where the string definition should be obtainedpublic LocalizableString(String key, ClassLoader loader, LocalizableString defaultValue)
String
. If a default value is not specified, if the key
is a valid URI, its fragment will be used, and otherwise the whole key
value will be used.key
- the localizable keyloader
- the ClassLoader
where the string definition should be obtaineddefaultValue
- the default value to use if not localizable.public String toTranslatedString(PreferredLocales locales)
locales
- The preferred locales for the translation.public String toString()
public boolean equals(Object o)
Copyright © 2010-2018, ForgeRock All Rights Reserved.