TContext
- the same class as TContext
for
I18nHandlerInContext
subclass being usedpublic class I18nItemInContext<TContext> extends I18nItem
The intermediate internationalized message storage and formatting class in
the hierarchy to implement an approach when user preferences may be retrieved
from an arbitrary generic TContext
instance; not intended to be used
or subclassed by applications directly.
See package info for a usage example.
Constructor and Description |
---|
I18nItemInContext(LocalizedMessage... data)
The public constructor.
|
Modifier and Type | Method and Description |
---|---|
String |
getBestLanguage(TContext contextData)
Similar to
#getBestLocaleTag(TContext) ,
but returns just the language field for the locale found. |
protected LocalizedMessage |
getBestLocaleAndMessage(TContext contextData)
A utility method to find both the best locale suitable for given user for
given
I18nItemInContext instance, and the appropriate message,
all represented as a LocalizedMessage instance. |
String |
getBestLocaleTag(TContext contextData)
Find the best match, exact or approximate, among locales available for
this item, for current user.
|
protected MessageFormat |
obtainMessageFormat(TContext contextData)
The method to obtain a localized
MessageFormat instance to be
used by subclasses that take message formatting arguments. |
getBestLanguage, getBestLocaleAndMessage, getBestLocaleTag, obtainMessageFormat
public I18nItemInContext(LocalizedMessage... data)
data
- a varargs array of translations for a message to various
localespublic String getBestLocaleTag(TContext contextData) throws NoSuchElementException
contextData
- an instance of context-specific data to retrieve user
preferences fromlocale language tag
NoSuchElementException
- should this instance happen to be emptypublic String getBestLanguage(TContext contextData) throws NoSuchElementException
#getBestLocaleTag(TContext)
,
but returns just the language field for the locale found. The method is
not used internally and is exposed as public for cases when an
application needs just information about best appropriate language.contextData
- an instance of context-specific data to retrieve user
preferences fromNoSuchElementException
- should this instance happen to be emptyprotected LocalizedMessage getBestLocaleAndMessage(TContext contextData)
I18nItemInContext
instance, and the appropriate message,
all represented as a LocalizedMessage
instance.contextData
- an instance of context-specific data to retrieve user
preferences fromLocalizedMessage
instance for the best locale guessprotected MessageFormat obtainMessageFormat(TContext contextData)
MessageFormat
instance to be
used by subclasses that take message formatting arguments.contextData
- an instance of context-specific data to retrieve user
preferences fromMessageFormat
instance