Package io.micronaut.context
Class AbstractLocalizedMessageSource<T>
java.lang.Object
io.micronaut.context.AbstractLocalizedMessageSource<T>
- Type Parameters:
T
- The context object which will be used to resolve the locale
- All Implemented Interfaces:
LocalizedMessageSource
- Direct Known Subclasses:
HttpLocalizedMessageSource
public abstract class AbstractLocalizedMessageSource<T>
extends Object
implements LocalizedMessageSource
Abstract class which implements
LocalizedMessageSource
and leverages LocaleResolver
API.- Since:
- 3.4.0
- Author:
- Sergio del Amo
-
Constructor Summary
ConstructorDescriptionAbstractLocalizedMessageSource
(LocaleResolver<T> localeResolver, MessageSource messageSource) -
Method Summary
Modifier and TypeMethodDescriptiongetMessage
(@NonNull String code) Resolve a message for the given code.getMessage
(@NonNull String code, Object... variables) Resolve a message for the given code and variables for the messages.Resolve a message for the given code and variables for the messages.resolveLocale
(T localeResolutionContext) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.context.LocalizedMessageSource
getMessageOrDefault, getMessageOrDefault, getMessageOrDefault
-
Constructor Details
-
AbstractLocalizedMessageSource
public AbstractLocalizedMessageSource(LocaleResolver<T> localeResolver, MessageSource messageSource) - Parameters:
localeResolver
- The locale resolvermessageSource
- The message source
-
-
Method Details
-
getLocale
- Returns:
- The resolved locale;
-
getMessage
@NonNull public @NonNull Optional<String> getMessage(@NonNull @NonNull String code, Object... variables) Resolve a message for the given code and variables for the messages.- Specified by:
getMessage
in interfaceLocalizedMessageSource
- Parameters:
code
- The codevariables
- to be used to interpolate the message- Returns:
- A message if present
-
getMessage
@NonNull public @NonNull Optional<String> getMessage(@NonNull @NonNull String code, Map<String, Object> variables) Resolve a message for the given code and variables for the messages.- Specified by:
getMessage
in interfaceLocalizedMessageSource
- Parameters:
code
- The codevariables
- to be used to interpolate the message- Returns:
- A message if present
-
getMessage
Description copied from interface:LocalizedMessageSource
Resolve a message for the given code.- Specified by:
getMessage
in interfaceLocalizedMessageSource
- Parameters:
code
- The code- Returns:
- A message if present
-
resolveLocale
- Parameters:
localeResolutionContext
- The context object which will be used to resolve the locale- Returns:
- The resolved locale;
-