Annotation Interface Message
The value of the key() can be used to reference a message in a template. It is possible to specify an explicit key
or a strategy to extract the default key. The default strategy is defined by the enclosing
MessageBundle.defaultKey().
The value() defines the template of a message. The method parameters can be used in this template. All the message
templates are validated at build time. If there is no template defined the template from a localized file is taken. In case
the value is not provided at all the build fails.
Note that any method declared on a message bundle interface is consireded a message bundle method. If not annotated with this annotation then the defaulted values are used for the key and template.
All message bundle methods must return String. If a message bundle method does not return string then the build
fails.
Enums
There is a convenient way to localize enums.If there is a message bundle method that accepts a single parameter of an enum type and has no message template defined then it receives a generated template like:
{#when enumParamName}
{#is CONSTANT1}{msg:methodName_CONSTANT1}
{#is CONSTANT2}{msg:methodName_CONSTANT2}
{/when}
Furthermore, a special message method is generated for each enum constant. Finally, each localized file must contain keys and
values for all enum constants.
methodName_CONSTANT1=Value 1 methodName_CONSTANT2=Value 2By default, the message key consists of the method name followed by the
_ separator and the constant name. If any
constant name of a particular enum contains the _ or the $ character then the _$ separator must be
used for all message keys for this enum instead. For example, methodName_$CONSTANT_1=Value 1 or
methodName_$CONSTANT$1=Value 1.
In a template, the localized message for an enum constant can be obtained with a message bundle method like
msg:methodName(enumConstant).- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionThe default template is only used ifvalue()is not specified and a message template is not defined in a localized file.The key of a message.This value has higher priority over a message template specified in a localized file, and it's considered a good practice to specify it. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringConstant value forkey()indicating that the default strategy specified byMessageBundle.defaultKey()should be used.static final StringConstant value forvalue()indicating that message template value specified in a localized file should be used.static final StringConstant value forkey()indicating that the annotated element's name should be used as-is.static final StringConstant value forkey()indicating that the annotated element's name should be de-camel-cased and hyphenated, and then used.static final StringConstant value forkey()indicating that the annotated element's name should be de-camel-cased and parts separated by underscores, and then used.
-
Field Details
-
DEFAULT_NAME
Constant value forkey()indicating that the default strategy specified byMessageBundle.defaultKey()should be used.- See Also:
-
ELEMENT_NAME
Constant value forkey()indicating that the annotated element's name should be used as-is.- See Also:
-
DEFAULT_VALUE
Constant value forvalue()indicating that message template value specified in a localized file should be used. If localized file fails to provide value, an exception is thrown and the build fails.- See Also:
-
HYPHENATED_ELEMENT_NAME
Constant value forkey()indicating that the annotated element's name should be de-camel-cased and hyphenated, and then used.- See Also:
-
UNDERSCORED_ELEMENT_NAME
Constant value forkey()indicating that the annotated element's name should be de-camel-cased and parts separated by underscores, and then used.- See Also:
-
-
Element Details
-
key
String keyThe key of a message.- Returns:
- the message key
- See Also:
- Default:
- "<<default>>"
-
value
String valueThis value has higher priority over a message template specified in a localized file, and it's considered a good practice to specify it. In case the value is not provided, there is no match in the localized file and thedefaultValue()is not specified, the build fails.There is a convenient way to localize enums. See the javadoc of
Message.- Returns:
- the message template
- Default:
- "<<default value>>"
-
defaultValue
String defaultValueThe default template is only used ifvalue()is not specified and a message template is not defined in a localized file.- Returns:
- the default message template
- Default:
- "<<default value>>"
-