@Singleton @Indexed(value=MessageSource.class) public interface MessageSource extends Ordered
Modifier and Type | Interface and Description |
---|---|
static interface |
MessageSource.MessageContext
The context to use.
|
Modifier and Type | Field and Description |
---|---|
static MessageSource |
EMPTY
An empty message source.
|
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Modifier and Type | Method and Description |
---|---|
default Optional<String> |
getMessage(String code,
Locale locale)
Resolve a message for the given code and context.
|
default Optional<String> |
getMessage(String code,
Locale locale,
Map<String,Object> variables)
Resolve a message for the given code and context.
|
default Optional<String> |
getMessage(String code,
Locale locale,
Object... variables)
Resolve a message for the given code and context.
|
default Optional<String> |
getMessage(String code,
MessageSource.MessageContext context)
Resolve a message for the given code and context.
|
default String |
getMessage(String code,
MessageSource.MessageContext context,
String defaultMessage)
Resolve a message for the given code and context.
|
default String |
getMessage(String code,
String defaultMessage,
Locale locale)
Resolve a message for the given code and context.
|
default String |
getMessage(String code,
String defaultMessage,
Locale locale,
Map<String,Object> variables)
Resolve a message for the given code and context.
|
default String |
getMessage(String code,
String defaultMessage,
Locale locale,
Object... variables)
Resolve a message for the given code and context.
|
Optional<String> |
getRawMessage(String code,
MessageSource.MessageContext context)
Resolve a message for the given code and context.
|
default String |
getRawMessage(String code,
MessageSource.MessageContext context,
String defaultMessage)
Resolve a message for the given code and context.
|
default String |
getRequiredMessage(String code,
MessageSource.MessageContext context)
Resolve a message for the given code and context or throw an exception.
|
default String |
getRequiredRawMessage(String code,
MessageSource.MessageContext context)
Resolve a message for the given code and context or throw an exception.
|
String |
interpolate(String template,
MessageSource.MessageContext context)
Interpolate the given message template.
|
static final MessageSource EMPTY
@NonNull default Optional<String> getMessage(@NonNull String code, @NonNull Locale locale)
code
- The codelocale
- The locale to use to resolve messages.@NonNull default Optional<String> getMessage(@NonNull String code, @NonNull Locale locale, @NonNull Object... variables)
code
- The codelocale
- The locale to use to resolve messages.variables
- The variables to use resolve message placeholders@NonNull default Optional<String> getMessage(@NonNull String code, @NonNull Locale locale, @NonNull Map<String,Object> variables)
code
- The codelocale
- The locale to use to resolve messages.variables
- The variables to use resolve message placeholders@NonNull default Optional<String> getMessage(@NonNull String code, @NonNull MessageSource.MessageContext context)
code
- The codecontext
- The context@NonNull default String getMessage(@NonNull String code, @NonNull String defaultMessage, @NonNull Locale locale)
code
- The codedefaultMessage
- The default message to use if no other message is foundlocale
- The locale to use to resolve messages.@NonNull default String getMessage(@NonNull String code, @NonNull String defaultMessage, @NonNull Locale locale, @NonNull Map<String,Object> variables)
code
- The codedefaultMessage
- The default message to use if no other message is foundlocale
- The locale to use to resolve messages.variables
- The variables to use resolve message placeholders@NonNull default String getMessage(@NonNull String code, @NonNull String defaultMessage, @NonNull Locale locale, @NonNull Object... variables)
code
- The codedefaultMessage
- The default message to use if no other message is foundlocale
- The locale to use to resolve messages.variables
- The variables to use resolve message placeholders@NonNull default String getMessage(@NonNull String code, @NonNull MessageSource.MessageContext context, @NonNull String defaultMessage)
code
- The codecontext
- The contextdefaultMessage
- The default message to use if no other message is found@NonNull Optional<String> getRawMessage(@NonNull String code, @NonNull MessageSource.MessageContext context)
code
- The codecontext
- The context@NonNull default String getRawMessage(@NonNull String code, @NonNull MessageSource.MessageContext context, @NonNull String defaultMessage)
code
- The codecontext
- The contextdefaultMessage
- The default message to use if no other message is found@NonNull String interpolate(@NonNull String template, @NonNull MessageSource.MessageContext context)
template
- The templatecontext
- The context to use.IllegalArgumentException
- If any argument specified is null@NonNull default String getRequiredMessage(@NonNull String code, @NonNull MessageSource.MessageContext context)
code
- The codecontext
- The contextNoSuchMessageException
- if the message is not found@NonNull default String getRequiredRawMessage(@NonNull String code, @NonNull MessageSource.MessageContext context)
code
- The codecontext
- The contextNoSuchMessageException
- if the message is not found