|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.mmm.util.nls.base.NlsCachingLocalizer
public class NlsCachingLocalizer
This is a class that stores messages and simplifies to
resolve them.
ATTENTION:
This class collects instances NlsMessage and NlsTemplate to
speed up repetitive translations. So only use this class for a dedicated set
of constant internationalized messages to
avoid memory leaks or supply an according MapFactory at construction.
| Field Summary | |
|---|---|
private String |
bundleName
The bundle-name. |
private NlsMessageFactory |
messageFactory
The NlsMessageFactory instance. |
private Map<String,NlsMessage> |
messagesMap
The Map used to cache messages. |
private static Pattern |
TEMPLATE_PATTERN
The pattern. |
private NlsTemplateResolver |
templateResolver
The NlsTemplateResolver instance. |
private Map<String,NlsTemplate> |
templatesMap
The Map used to cache templates. |
| Constructor Summary | |
|---|---|
NlsCachingLocalizer(String bundleName)
The constructor. |
|
NlsCachingLocalizer(String bundleName,
NlsMessageFactory messageFactory,
NlsTemplateResolver templateResolver)
The constructor. |
|
NlsCachingLocalizer(String bundleName,
NlsMessageFactory messageFactory,
NlsTemplateResolver templateResolver,
MapFactory<? extends Map> mapFactory)
The constructor. |
|
| Method Summary | |
|---|---|
String |
localize(Locale locale,
String internationalizedMessage)
This method localizes the given internationalizedMessage to
the given target locale. |
String |
localize(Locale locale,
String internationalizedMessage,
Map<String,Object> arguments)
This method localizes the given internationalizedMessage with
the given arguments filled in to the given target
locale. |
protected NlsTemplate |
parseTemplate(String internationalizedMessage)
This method parses the given internationalizedMessage as
NlsTemplate in case it is given in the form
{<BUNDLE>#<KEY>}. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final Pattern TEMPLATE_PATTERN
private final NlsMessageFactory messageFactory
NlsMessageFactory instance.
private final NlsTemplateResolver templateResolver
NlsTemplateResolver instance.
private final Map<String,NlsMessage> messagesMap
Map used to cache messages.
private final Map<String,NlsTemplate> templatesMap
Map used to cache templates.
private final String bundleName
bundle-name.
| Constructor Detail |
|---|
public NlsCachingLocalizer(String bundleName)
bundleName - is the default
bundle-name.
public NlsCachingLocalizer(String bundleName,
NlsMessageFactory messageFactory,
NlsTemplateResolver templateResolver)
bundleName - is the default
bundle-name.messageFactory - is the NlsMessageFactory instance.templateResolver - is the NlsTemplateResolver instance.
public NlsCachingLocalizer(String bundleName,
NlsMessageFactory messageFactory,
NlsTemplateResolver templateResolver,
MapFactory<? extends Map> mapFactory)
bundleName - is the default
bundle-name.messageFactory - is the NlsMessageFactory instance.templateResolver - is the NlsTemplateResolver instance.mapFactory - is the MapFactory used to create caches for the
the messages and templates.| Method Detail |
|---|
protected NlsTemplate parseTemplate(String internationalizedMessage)
internationalizedMessage as
NlsTemplate in case it is given in the form
{<BUNDLE>#<KEY>}.
internationalizedMessage - is the template specified in the form
described above or the
internationalized
message.
NlsTemplate if the
internationalizedMessage has the form described above
or null otherwise.
public String localize(Locale locale,
String internationalizedMessage,
Map<String,Object> arguments)
internationalizedMessage with
the given arguments filled in to the given target
locale.
localize in interface NlsLocalizerlocale - is the Locale to translate to.internationalizedMessage - is the
internationalized
message to translate.arguments - are the arguments
to fill in.
public String localize(Locale locale,
String internationalizedMessage)
internationalizedMessage to
the given target locale.
localize in interface NlsLocalizerlocale - is the Locale to translate to.internationalizedMessage - is the
internationalized
message to translate.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||