See: Description
Class | Description |
---|---|
I15dLogger |
An internationalized (i15d) logger class for SLF4J.
|
I15dLoggerFactory |
An internationalized (i15d) logger factory class for SLF4J.
|
I18nHandler |
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.
|
I18nHandlerForServletRequest |
This
I18nHandlerInContext subclass is ready-to-use to implement
the approach with user locale preferences being retrieved from
ServletRequest Accept-Language
headers. |
I18nHandlerForSingleUser |
This
I18nHandler subclass is almost ready-to-use to implement the
approach with user locale preferences being stored locally, allowing single
user per application instance. |
I18nHandlerInContext<TContext> |
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. |
I18nItem |
The basic internationalized message storage and formatting class in the
hierarchy; not intended to be used or subclassed by applications
directly.
|
I18nItem0 |
A class that implements multi-locale resource without formatting
arguments, to be used together with
I18nHandler subclasses. |
I18nItem1<TArg1> |
A class that implements multi-locale resource in
MessageFormat style with one argument, to be
used together with I18nHandler subclasses. |
I18nItem2<TArg1,TArg2> |
A class that implements multi-locale resource in
MessageFormat style with two arguments, to be
used together with I18nHandler subclasses. |
I18nItem3<TArg1,TArg2,TArg3> |
A class that implements multi-locale resource in
MessageFormat style with three arguments, to
be used together with I18nHandler subclasses. |
I18nItemAny |
A class that implements multi-locale resource in
MessageFormat style with arbitrary number of
arguments, to be used together with I18nHandler subclasses. |
I18nItemInContext<TContext> |
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. |
I18nItemInContext0<TContext> |
A class that implements multi-locale resource without formatting
arguments, to be used together with
I18nHandlerInContext
subclasses. |
I18nItemInContext1<TContext,TArg1> |
A class that implements multi-locale resource in
MessageFormat style with one argument, to be
used together with I18nHandlerInContext subclasses. |
I18nItemInContext2<TContext,TArg1,TArg2> |
A class that implements multi-locale resource in
MessageFormat style with two arguments, to be
used together with I18nHandlerInContext subclasses. |
I18nItemInContext3<TContext,TArg1,TArg2,TArg3> |
A class that implements multi-locale resource in
MessageFormat style with three arguments, to
be used together with I18nHandlerInContext subclasses. |
I18nItemInContextAny<TContext> |
A class that implements multi-locale resource in
MessageFormat style with arbitrary number of
arguments, to be used together with I18nHandlerInContext
subclasses. |
LocalizedMessage |
A utility class to facilitate construction and identification of localized
messages, with messages being allowed to take
MessageFormat -style arguments upon being
used. |
This package implements an alternative to traditional approach to Java software internationalization and allows localized resources be referenced via individual class member names rather than by arbitrary strings. This allows localized resource references be checked at compile time and also facilitates taking advantage of autocompletion aids provided by IDE's.
An application using this package would normally:
I18nHandler
subclass
singleton linked to user preferences in an arbitrary application
specific manner, possibly queried with the application or specified
as part of persisted user preferences in
single-user-per-application-instance cases, etc;
I18nHandlerInContext
subclass singleton capable of detecting user
preferences dynamically from an arbitrary application specific
context; such contexts may be constituted, without limitation, by
ServletRequest
,
HttpSession
, etc;
I18nHandler
or
I18nHandlerInContext
,
providing an application-specific
getUserLocaleTags()
method and optionally an application-specific
getDefaultLocaleTag()
method;I18nItem
subclass instances,
one for every message that requires being internationalized; feel free to
have them all in one place or scatter them across your package tree to
your best convenience;.s()
method being called.The following classes are intended for direct use by applications:
I18nHandler
– to be subclassed by multi-user applications in cases when no
explicit user context is available, but it is possible to retrieve
user preferences from the application itself;I18nHandlerInContext
– to be subclassed by multi-user
applications in cases when some sort of user context is available to
retrieve user preferences from, like
ServletRequest
,
HttpSession
, etc;I18nHandlerForSingleUser
– a ready-to-use handler class
suitable for single-user (e.g. desktop) applications in cases when
it is possible to retrieve user preferences once on application
initialization;I18nHandlerForServletRequest
– a ready-to-use handler class
suitable for HTTP server applications;I18nHandlerInContext
subclasses; they have 'InContext' suffix in
their names;I18nHandler
subclasses,
I18nHandlerSingleUser
included; they do not have any
context-related suffix in their names;I15dLogger
and appropriate
factory
I15dLoggerFactory
.An example of "hello world" application:
import usn.i18n.nobundle.I15dLogger; import usn.i18n.nobundle.I15dLoggerFactory; import usn.i18n.nobundle.I18nHandler; import usn.i18n.nobundle.I18nItem0; import usn.i18n.nobundle.I18nItemAny; import static usn.i18n.nobundle.LocalizedMessage.lm; public class MyApplication { // only 'I18nItemAny' message items are currently supported for logger static I18nItemAny LOG_MSG_HELLO = new I18nItemAny (lm ("en", "Hello World!"), lm ("fr_CA", "Bonjour Monde!"))); public static I18nItem0 USER_MESSAGE_1 = new I18nItem0 (lm ("en", "That's cool!"), lm ("fr_CA", "C'est le pied!")); public static void main (String [] args) { // the 'i18nHandler' variable itself is not needed, // we just need to istantiate some 'I18nHandler' subclass, // and we do it here subclassing 'I18nHandler' anonymously @SuppressWarnings ("unused") I18nHandler i18nHandler = new I18nHandler () { @Override protected String getDefaultLocaleTag () { return "fr_CA"; } // getDefaultLocaleTag @Override protected String [] getUserLocaleTags () { // do something application-specific here... } // getUserLocaleTags }; I15dLogger logger = I15dLoggerFactory.getLogger (MyApplication.class); // for messages without arguments we can use .toString() implicitly // instead of explicit .s() logger.info (LOG_MSG_HELLO); System.out.println (USER_MESSAGE_1.s ()); } // main } // class MyApplication