public interface NlsMessage extends NlsObject, Serializable
internationalized-message separated from language independent arguments. This approach
ensures that the message is always available in the internationalized language (should be English) while it still
allows to translate the message to a native language. For
an introduction first read hereinternationalized-message is (almost) compatible to
MessageFormat. This allows to migrate existing code from MessageFormat to
NlsMessage easily. However, there are some advanced features available. While using numbers to identify the
argument is a maintenance-hell for large messages, it is also possible to use
named arguments. Further there is also support for additional styles as well as
Justification. See NlsArgument for the specification of the argument
syntax.NlsMessages you create an NlsBundle per module.
For the term internationalization usually the shortcut i18n is used.NlsArgument,
NlsBundle,
NlsMessageFactory,
net.sf.mmm.util.nls.api| Modifier and Type | Field and Description |
|---|---|
static String |
LOCALIZATION_FAILURE_PREFIX
The prefix appended to the
message if the localization (translation) failed. |
KEY_ANNOTATION, KEY_ARGUMENT, KEY_CAPACITY, KEY_CONTAINER, KEY_DEFAULT, KEY_DIRECTORY, KEY_ERROR, KEY_EXISTING, KEY_EXPECTED, KEY_FILE, KEY_FUNCTION, KEY_ID, KEY_KEY, KEY_LOCATION, KEY_MAX, KEY_MIN, KEY_MODE, KEY_NAME, KEY_OBJECT, KEY_OPERAND, KEY_OPERATION, KEY_OPTION, KEY_PATH, KEY_PROPERTY, KEY_QUERY, KEY_RESOURCE, KEY_SIZE, KEY_SOURCE, KEY_TARGET_TYPE, KEY_TITLE, KEY_TYPE, KEY_URI, KEY_USER, KEY_VALUE| Modifier and Type | Method and Description |
|---|---|
Object |
getArgument(int index)
Deprecated.
use
getArgument(String) instead (and use named keys instead of numbers where possible). |
Object |
getArgument(String key)
This method gets the language independent argument value for the given
key. |
int |
getArgumentCount()
Deprecated.
this method does NOT make sense anymore.
|
String |
getInternationalizedMessage()
This method gets the internationalized message what is the actual message template for the
root
locale without resolving its NlsArguments. |
String |
getLocalizedMessage()
|
String |
getLocalizedMessage(Locale locale)
This method gets the resolved and localized message.
First it will translate the
internationalized message to the given Locale. |
void |
getLocalizedMessage(Locale locale,
Appendable buffer)
This method writes the
localized message to the given buffer. |
String |
getLocalizedMessage(Locale locale,
NlsTemplateResolver resolver)
Deprecated.
providing external
NlsTemplateResolver has been discouraged. |
void |
getLocalizedMessage(Locale locale,
NlsTemplateResolver resolver,
Appendable buffer)
Deprecated.
providing external
NlsTemplateResolver has been discouraged. |
String |
getMessage()
This method gets the untranslated message (default language should be English) with arguments filled in.
|
toNlsMessagestatic final String LOCALIZATION_FAILURE_PREFIX
message if the localization (translation) failed.String getInternationalizedMessage()
root
locale without resolving its NlsArguments."Welcome {name}!").NlsMessage,
getArgument(String),
MessageFormat@Deprecated int getArgumentCount()
Object getArgument(String key)
key.key - is the name of the requested argument.null if NOT defined.NlsArgument@Deprecated Object getArgument(int index)
getArgument(String) instead (and use named keys instead of numbers where possible).index.index - is the index of the requested argument.String getMessage()
getLocalizedMessage(Locale) instead of this method.getLocalizedMessage(Locale, NlsTemplateResolver)String getLocalizedMessage()
localized message as String using the
default Locale. In the simplest case Locale.getDefault() is used but if available
LocaleContextHolder from spring is used.getLocalizedMessage(Locale) instead.String getLocalizedMessage(Locale locale)
translate the
internationalized message to the given Locale. If this fails for
whatever reason, the internationalized message is used as fallback.arguments with their according
values.internationalized message is "Welcome {name}!"
and the argument with the key @c"name" has the value "Joelle". After
translation to Locale.GERMAN the message may be "Willkommen {name}!". This results in the
resolved message "Willkommen Joelle!". If the German localization was not present or has a syntax error,
the root locale is used as fallback result in "Welcome Joelle!".locale - is the locale to translate to.net.sf.mmm.util.nls.apivoid getLocalizedMessage(Locale locale, Appendable buffer)
locale - is the locale to translate to.buffer - is the buffer where to write the message to.getLocalizedMessage(Locale)@Deprecated String getLocalizedMessage(Locale locale, NlsTemplateResolver resolver)
NlsTemplateResolver has been discouraged.locale - is the locale to translate to.resolver - is used to translate the message.getLocalizedMessage(Locale, NlsTemplateResolver, Appendable)@Deprecated void getLocalizedMessage(Locale locale, NlsTemplateResolver resolver, Appendable buffer)
NlsTemplateResolver has been discouraged.buffer. template that is provided via the given resolver.
If this fails, the original message will be used. After translation is done,
the language independent arguments will be filled in the translated message string according to the given
locale.locale - is the locale to translate to.resolver - is used to resolve the template required to translate the internationalized message.buffer - is the buffer where to write the message to.Copyright © 2001–2016 mmm-Team. All rights reserved.