Package org.forgerock.util.i18n
Class LocalizableString
java.lang.Object
org.forgerock.util.i18n.LocalizableString
Represents a String which could be localizable. If it is localizable it needs to be in the following format,
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, aClass
has to be provided and will be used as resource bundle name)key
, the fragment, is the key of the translated string
ClassLoader
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.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
A constant used to indicate a string should be translated. -
Constructor Summary
ConstructorDescriptionLocalizableString
(String value) String only constructor for non-localizableString
values.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
Modifier and TypeMethodDescriptionboolean
The default equals operation.int
hashCode()
Default hashcode implementation.toString()
The default toString method.toTranslatedString
(PreferredLocales locales) Returns the contained string, translated if applicable.
-
Field Details
-
TRANSLATION_KEY_PREFIX
A constant used to indicate a string should be translated.- See Also:
-
-
Constructor Details
-
LocalizableString
String only constructor for non-localizableString
values.- Parameters:
value
- a string
-
LocalizableString
Constructor for potentially localizableString
. If resource bundle name not provided in thevalue
, then the providedtype
name 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
Constructor for potentially localizableString
.- Parameters:
value
- the Stringloader
- theClassLoader
where the string definition should be obtained
-
LocalizableString
Constructor for potentially localizableString
. If a default value is not specified, if thekey
is a valid URI, its fragment will be used, and otherwise the wholekey
value will be used.- Parameters:
key
- the localizable keyloader
- theClassLoader
where the string definition should be obtaineddefaultValue
- the default value to use if not localizable.
-
-
Method Details
-
toTranslatedString
Returns the contained string, translated if applicable.- Parameters:
locales
- The preferred locales for the translation.- Returns:
- the translated string
-
toString
The default toString method. No translation is applied. -
equals
The default equals operation. -
hashCode
public int hashCode()Default hashcode implementation.
-