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 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. The format specification for
parameter-syntax is as following:
'{' ArgumentKey [ ',' FormatType [ ',' FormatStyle ] ] [ '{' Justification '}' ] '}'
The literals are explained in this table.
| literal | explanation |
|---|---|
| ArgumentKey | is the key of the parameter (may be numeric for legacy support) |
| FormatType | a type specifying how to format the value (see below). Should fit to the type
of the value.
|
| FormatStyle | a style according to FormatType (see below). |
| Justification | a justification |
FormatType and FormatStyle:
| FormatType | FormatStyle | Example | Comment |
|---|---|---|---|
| - | - | value as string | default string representation of the value |
number |
- | 123,456.78 | Numeric representation |
number |
percent |
12,345,678% | Number in percent |
number |
currency |
123,456.78 � | Number as currency |
number |
'#'##.## | #123456.78 | Any other style is treated as pattern for DecimalFormat |
date |
- | 31-Dec-1999 | Date default representation |
date |
short |
31/12/99 | Date short representation |
date |
medium |
31-Dec-1999 | Date medium representation |
date |
long |
31 December 1999 | Date long representation |
date |
full |
Friday, 31 December 1999 | Date full representation |
date |
iso8601 |
1999-12-31 | Date ISO-8601 representation |
date |
yyyy.MM.dd | 2010.01.01 | Any other style is treated as pattern for SimpleDateFormat |
time |
- | 23:59:59 | Time default representation |
time |
short |
23:59 | Time short representation |
time |
medium |
23:59:59 | Time medium representation |
time |
long |
23:59:59 GMT+01:00 | Time long representation |
time |
full |
23:59:59 o'clock GMT+01:00 | Time full representation |
time |
iso8601 |
23:59:59+01:00 | Time ISO-8601 representation |
time |
HH:mm:ss | 23:59:59 | Any other style is treated as pattern for SimpleDateFormat |
datetime |
- | 31-Dec-1999 23:59:59 | Date+time default representation |
datetime |
short |
31/12/99 23:59 | Date+time short representation |
datetime |
medium |
31-Dec-1999 23:59:59 | Date+time medium representation |
datetime |
long |
31 December 1999 23:59:59 GMT+01:00 | Date+time long representation |
datetime |
full |
Friday, 31 December 1999 23:59:59 o'clock GMT+01:00 | Date+time full representation |
datetime |
iso8601 |
1999-12-31T23:59:59+01:00 | Date+time ISO-8601 representation |
date |
yyyy.MM.dd-HH:mm:ss | 2010.01.01-23:59:59 | Any other style is treated as pattern for SimpleDateFormat |
type |
- | java.util.List | Type medium representation (omit java.lang) |
type |
short |
List | Type short representation |
type |
medium |
java.util.List | Type medium representation (omit java.lang) |
type |
long |
java.util.List<String> | Type long representation |
type |
full |
java.util.List<java.lang.String> | Type full representation |
choice |
(?==1)'error'(else)'errors' | error | A choice to distinguish singular/plural forms. |
choice |
(?>=5){key,choice,(?==true)'a'(else){key2}}(else)'c' | a | A choice that results to 'c' if the value is NOT greater or equal to 5. Otherwise it results to 'a' if
the value of the argument "key" is Boolean.TRUE. Otherwise it results to the value of the argument
"key2". - This is a wired example. It shows the power of the choice format as well as how things turn out
unmaintainable if the power is missused. |
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 for the given
key. |
int |
getArgumentCount()
Deprecated.
this method does NOT make sense anymore.
|
String |
getInternationalizedMessage()
This method gets the internationalized message that can be
translated to a native language. |
String |
getLocalizedMessage()
|
String |
getLocalizedMessage(Locale locale)
This method gets the message localized to the given
Locale as string. |
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()
translated to a native language. The language
independent arguments are filled into the message after the translation process. "Welcome {name}!" and there is one argument that is the string
"Joelle". The final result will then be "Welcome Joelle!". If the message is
translated to German as "Willkommen {name}!" the final result will be
"Willkommen Joelle!".NlsMessage,
getArgument(String),
MessageFormat@Deprecated int getArgumentCount()
Object getArgument(String key)
key.key - is the name of the requested argument.null if NOT defined.@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()
default
Locale. getLocalizedMessage(Locale) instead.String getLocalizedMessage(Locale locale)
Locale as string. If this fails for whatever
reason, the untranslated message will be returned as fallback.locale - is the locale to translate to.net.sf.mmm.util.nls.apivoid getLocalizedMessage(Locale locale, Appendable buffer)
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.buffer - is the buffer where to write the message to.@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–2015 mmm-Team. All rights reserved.