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#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
Fields Modifier and Type Field Description static String
TRANSLATION_KEY_PREFIX
A constant used to indicate a string should be translated.
-
Constructor Summary
Constructors Constructor Description LocalizableString(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
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
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-localizableString
values.- 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 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
public LocalizableString(String value, ClassLoader loader)
Constructor for potentially localizableString
.- Parameters:
value
- the Stringloader
- theClassLoader
where 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 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 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.
-
-