-
- All Superinterfaces:
LocalizableObject
- All Known Subinterfaces:
NlsMessage
,ValidationResult
- All Known Implementing Classes:
AbstractValidationResult
,ApplicationException
,CliArgumentMandatoryException
,CliDuplicateOptionAliasException
,CliDuplicateOptionsException
,CliException
,CliInvalidUsageException
,CliNoArgumentsException
,CliTypeNotExtendingException
,ComposedValidationFailure
,DuplicateObjectException
,ObjectMismatchException
,ObjectNotFoundException
,ObjectNotFoundUserException
,ReadOnlyException
,RuntimeIoException
,TechnicalErrorUserException
,ValidationFailure
,ValidationResultValid
public interface Localizable extends LocalizableObject
Interface for an object that can betranslated
to a givenLocale
. It is the API to abstract fromNlsMessage
provided bymmm-nls
. To minimize dependencies you can mock it withofStatic(String)
wrapping a regularString
. For real native language support (NLS) addmmm-nls
as dependency and require moduleio.github.mmm.nls
.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static String
createBundleName(Class<?> type)
default Object
getArgument(String key)
This method gets the language independent argument value for the givenkey
.default String
getLocalizedMessage()
default String
getLocalizedMessage(Locale locale)
This method gets the resolved and localized message.void
getLocalizedMessage(Locale locale, Appendable buffer)
This method writes thelocalized message
to the givenAppendable
.default String
getMessage()
ATTENTION:
In most cases you wand to usegetLocalizedMessage(Locale)
instead of this method.static Localizable
ofStatic(String message)
default Localizable
toLocalizable()
This method is the equivalent toObject.toString()
with native language support.
-
-
-
Method Detail
-
getMessage
default String getMessage()
ATTENTION:
In most cases you wand to usegetLocalizedMessage(Locale)
instead of this method.- Returns:
- the untranslated message with arguments filled in. This results in the message in its original language that should typically be English.
- See Also:
getLocalizedMessage()
-
getLocalizedMessage
default String getLocalizedMessage()
This method tries to get thelocalized message
asString
using thedefault locale
. ATTENTION:
If possible try to avoid using this method and usegetLocalizedMessage(Locale)
instead (e.g. using springLocaleContextHolder
to get the users locale).- Returns:
- the localized message.
-
getLocalizedMessage
default String getLocalizedMessage(Locale locale)
This method gets the resolved and localized message.- Parameters:
locale
- is the locale to translate to.- Returns:
- the localized message.
-
getLocalizedMessage
void getLocalizedMessage(Locale locale, Appendable buffer)
- Parameters:
locale
- theLocale
to translate to.buffer
- theAppendable
where towrite
the message to.- See Also:
getLocalizedMessage(Locale)
-
toLocalizable
default Localizable toLocalizable()
Description copied from interface:LocalizableObject
This method is the equivalent toObject.toString()
with native language support.- Specified by:
toLocalizable
in interfaceLocalizableObject
- Returns:
- an
Localizable
representing this object.
-
getArgument
default Object getArgument(String key)
This method gets the language independent argument value for the givenkey
.- Parameters:
key
- is the name of the requested argument.- Returns:
- the argument value for the given key or
null
if NOT defined.
-
ofStatic
static Localizable ofStatic(String message)
- Parameters:
message
- themessage
.- Returns:
- a dummy implementation of
Localizable
for the givenmessage
that does not support localization and simply ignores any givenLocale
.
-
-