public class I18nHandler extends Object
The basic handler class in the hierarchy that implements an approach when user preferences are either retrieved from the application or stored locally in single-user-per-application-instance cases; to be subclassed by an application.
This class specifies the most basic handler methods. It also declares and
sustains an I18nHandler singleton to be used by I18nItem
subclasses.
An application would normally subclass this class and:
getUserLocaleTags() method;getDefaultLocaleTag() method;See package info for a usage example.
| Modifier | Constructor and Description |
|---|---|
protected |
I18nHandler()
The no-argument constructor to be used by subclasses.
|
| Modifier and Type | Method and Description |
|---|---|
protected String |
findBestLocaleTag(I18nItem item)
|
protected String |
findBestLocaleTag(I18nItem item,
String[] userLocaleTags)
The core method to be used by
I18nHandler subclasses to find
the best locale suitable for given user for given I18nItem
instance, with user locale preferences already having been identified. |
protected String |
getDefaultLocaleTag()
The method to be used internally to obtain the application-wide default
locale; to be overridden, should the application-wide default locale
be different from the system locale.
|
protected String[] |
getUserLocaleTags()
The method to be used internally to obtain an array of user's preferred
locales, identified via their
language tags, best preferred coming
first; to be overridden to implement an application-specific approach to
user locale preferences. |
static Locale |
localeForLanguageTag(String localeTag)
The procedure to query and populate the local locale cache, indexed by
language tags; made public to allow
I18nItem subclassing. |
protected I18nHandler()
I18nHandler singleton.public static Locale localeForLanguageTag(String localeTag)
I18nItem subclassing.localeTag - the locale language tag
to query forLocale instance, either from cache or newprotected String findBestLocaleTag(I18nItem item, String[] userLocaleTags) throws NoSuchElementException
I18nHandler subclasses to find
the best locale suitable for given user for given I18nItem
instance, with user locale preferences already having been identified.
Tries to find a match for user preferences first, either exact match for
user preferred locale or approximate match for language part thereof,
then for application default locale, then for any English flavor, and
finally tries to return just anything available. In case of several
locales available for one language in the I18nItem instance, and
only language being matched, the last locale supplied upon item
construction wins.item - an internationalized message instanceuserLocaleTags - an array of user preferred locales represented by
their language tags,
best preferred coming firstlanguage tag for the best suitable
locale foundNoSuchElementException - should the item happen to be emptyprotected String findBestLocaleTag(I18nItem item) throws NoSuchElementException
I18nItem subclasses to find the
best locale suitable for given user for given I18nItem
instance.item - an I18nItem instance to be servedlanguage tag for the best suitable
locale foundNoSuchElementException - should the item happen to be emptyprotected String getDefaultLocaleTag()
locale language tag for
default locale of an applicationprotected String[] getUserLocaleTags()
language tags, best preferred coming
first; to be overridden to implement an application-specific approach to
user locale preferences. A subclass may retrieve user locale preferences
either by querying the application or simply storing user preferences
locally like I18nHandlerForSingleUser.locale language tags
for user's preferred locales, best preferred coming first