Package io.micronaut.context
Interface MessageSource
- All Superinterfaces:
Ordered
- All Known Implementing Classes:
AbstractMessageSource
,CompositeMessageSource
,ResourceBundleMessageSource
,StaticMessageSource
Interface for resolving messages from some source.
- Since:
- 1.2
- Author:
- graemerocher
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
The context to use. -
Field Summary
Fields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Method Summary
Modifier and TypeMethodDescriptiongetMessage
(@NonNull String code, @NonNull MessageSource.MessageContext context) Resolve a message for the given code and context.getMessage
(@NonNull String code, @NonNull MessageSource.MessageContext context, @NonNull String defaultMessage) Resolve a message for the given code and context.Resolve a message for the given code and context.getMessage
(@NonNull String code, @NonNull String defaultMessage, @NonNull Locale locale, @NonNull Object... variables) Resolve a message for the given code and context.getMessage
(@NonNull String code, @NonNull String defaultMessage, @NonNull Locale locale, @NonNull Map<String, Object> variables) Resolve a message for the given code and context.getMessage
(@NonNull String code, @NonNull Locale locale) Resolve a message for the given code and context.Resolve a message for the given code and context.Resolve a message for the given code and context.getRawMessage
(@NonNull String code, @NonNull MessageSource.MessageContext context) Resolve a message for the given code and context.getRawMessage
(@NonNull String code, @NonNull MessageSource.MessageContext context, @NonNull String defaultMessage) Resolve a message for the given code and context.getRequiredMessage
(@NonNull String code, @NonNull MessageSource.MessageContext context) Resolve a message for the given code and context or throw an exception.getRequiredRawMessage
(@NonNull String code, @NonNull MessageSource.MessageContext context) Resolve a message for the given code and context or throw an exception.interpolate
(@NonNull String template, @NonNull MessageSource.MessageContext context) Interpolate the given message template.
-
Field Details
-
EMPTY
An empty message source.
-
-
Method Details
-
getMessage
@NonNull default @NonNull Optional<String> getMessage(@NonNull @NonNull String code, @NonNull @NonNull Locale locale) Resolve a message for the given code and context.- Parameters:
code
- The codelocale
- The locale to use to resolve messages.- Returns:
- A message if present
-
getMessage
@NonNull default @NonNull Optional<String> getMessage(@NonNull @NonNull String code, @NonNull @NonNull Locale locale, @NonNull @NonNull Object... variables) Resolve a message for the given code and context.- Parameters:
code
- The codelocale
- The locale to use to resolve messages.variables
- The variables to use resolve message placeholders- Returns:
- A message if present
-
getMessage
@NonNull default @NonNull Optional<String> getMessage(@NonNull @NonNull String code, @NonNull @NonNull Locale locale, @NonNull @NonNull Map<String, Object> variables) Resolve a message for the given code and context.- Parameters:
code
- The codelocale
- The locale to use to resolve messages.variables
- The variables to use resolve message placeholders- Returns:
- A message if present
-
getMessage
@NonNull default @NonNull Optional<String> getMessage(@NonNull @NonNull String code, @NonNull @NonNull MessageSource.MessageContext context) Resolve a message for the given code and context.- Parameters:
code
- The codecontext
- The context- Returns:
- A message if present
-
getMessage
@NonNull default @NonNull String getMessage(@NonNull @NonNull String code, @NonNull @NonNull String defaultMessage, @NonNull @NonNull Locale locale) Resolve a message for the given code and context.- Parameters:
code
- The codedefaultMessage
- The default message to use if no other message is foundlocale
- The locale to use to resolve messages.- Returns:
- A message if present
-
getMessage
@NonNull default @NonNull String getMessage(@NonNull @NonNull String code, @NonNull @NonNull String defaultMessage, @NonNull @NonNull Locale locale, @NonNull @NonNull Map<String, Object> variables) Resolve a message for the given code and context.- Parameters:
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- Returns:
- A message if present
-
getMessage
@NonNull default @NonNull String getMessage(@NonNull @NonNull String code, @NonNull @NonNull String defaultMessage, @NonNull @NonNull Locale locale, @NonNull @NonNull Object... variables) Resolve a message for the given code and context.- Parameters:
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- Returns:
- A message if present
-
getMessage
@NonNull default @NonNull String getMessage(@NonNull @NonNull String code, @NonNull @NonNull MessageSource.MessageContext context, @NonNull @NonNull String defaultMessage) Resolve a message for the given code and context.- Parameters:
code
- The codecontext
- The contextdefaultMessage
- The default message to use if no other message is found- Returns:
- A message if present
-
getRawMessage
@NonNull @NonNull Optional<String> getRawMessage(@NonNull @NonNull String code, @NonNull @NonNull MessageSource.MessageContext context) Resolve a message for the given code and context.- Parameters:
code
- The codecontext
- The context- Returns:
- A message if present
-
getRawMessage
@NonNull default @NonNull String getRawMessage(@NonNull @NonNull String code, @NonNull @NonNull MessageSource.MessageContext context, @NonNull @NonNull String defaultMessage) Resolve a message for the given code and context.- Parameters:
code
- The codecontext
- The contextdefaultMessage
- The default message to use if no other message is found- Returns:
- A message if present
-
interpolate
@NonNull @NonNull String interpolate(@NonNull @NonNull String template, @NonNull @NonNull MessageSource.MessageContext context) Interpolate the given message template.- Parameters:
template
- The templatecontext
- The context to use.- Returns:
- The interpolated message.
- Throws:
IllegalArgumentException
- If any argument specified is null
-
getRequiredMessage
@NonNull default @NonNull String getRequiredMessage(@NonNull @NonNull String code, @NonNull @NonNull MessageSource.MessageContext context) Resolve a message for the given code and context or throw an exception.- Parameters:
code
- The codecontext
- The context- Returns:
- The message
- Throws:
NoSuchMessageException
- if the message is not found
-
getRequiredRawMessage
@NonNull default @NonNull String getRequiredRawMessage(@NonNull @NonNull String code, @NonNull @NonNull MessageSource.MessageContext context) Resolve a message for the given code and context or throw an exception.- Parameters:
code
- The codecontext
- The context- Returns:
- The message
- Throws:
NoSuchMessageException
- if the message is not found
-