public class NlsCachingLocalizer extends Object implements NlsLocalizer
messages and simplifies to resolve them. 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.| Modifier and Type | Field and Description |
|---|---|
private String |
bundleName
The
bundle-name. |
private NlsMessageFactory |
messageFactory
The
NlsMessageFactory instance. |
private Map<String,NlsMessage> |
messagesMap
|
private static Pattern |
TEMPLATE_PATTERN
The pattern.
|
private NlsTemplateResolver |
templateResolver
The
NlsTemplateResolver instance. |
private Map<String,NlsTemplate> |
templatesMap
|
| Constructor and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
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>}. |
private static final Pattern TEMPLATE_PATTERN
private final NlsMessageFactory messageFactory
NlsMessageFactory instance.private final NlsTemplateResolver templateResolver
NlsTemplateResolver instance.private final Map<String,NlsMessage> messagesMap
private final Map<String,NlsTemplate> templatesMap
private final String bundleName
bundle-name.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.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)
NlsLocalizerinternationalizedMessage 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)
NlsLocalizerinternationalizedMessage to the given target locale.localize in interface NlsLocalizerlocale - is the Locale to translate to.internationalizedMessage - is the internationalized message
to translate.Copyright © 2001–2016 mmm-Team. All rights reserved.