TContext
- an arbitrary class that might be used to retrieve user
locale preferences frompublic class I18nHandlerInContext<TContext> extends I18nHandler
The intermediate handler class in the hierarchy to implement an approach
when user preferences may be retrieved from an arbitrary generic
TContext
instance; to be subclassed by an application.
An application using this approach would normally subclass this class and:
getUserLocaleTags(TContext)
method;I18nHandler.getDefaultLocaleTag()
method;See package info for a usage example.
Constructor and Description |
---|
I18nHandlerInContext() |
Modifier and Type | Method and Description |
---|---|
protected String |
findBestLocaleTag(TContext contextData,
I18nItemInContext<TContext> item)
A utility method to be used by
I18nItemInContext subclasses to
find the best locale suitable for given user for given
I18nItemInContext instance. |
protected String[] |
getUserLocaleTags(TContext contextData)
The method to be used internally to obtain an array of user's preferred
locales, identified via their
language tags , best preferred coming
first. |
findBestLocaleTag, findBestLocaleTag, getDefaultLocaleTag, getUserLocaleTags, localeForLanguageTag
protected String findBestLocaleTag(TContext contextData, I18nItemInContext<TContext> item)
I18nItemInContext
subclasses to
find the best locale suitable for given user for given
I18nItemInContext
instance.contextData
- an instance of context-specific data to retrieve user
preferences fromitem
- an I18nItemInContext
instance to be servedlanguage tag
for the best suitable
locale foundprotected String[] getUserLocaleTags(TContext contextData)
language tags
, best preferred coming
first. The default implementation just calls the corresponding
superclass' argumentless method. To be overridden to implement an
application-specific approach to user locale preferences. A subclass is
expected to retrieve user locale preferences via the contextData
argument.contextData
- an instance of context-specific data to retrieve user
preferences fromlocale language tags
for user's preferred locales, best preferred coming first