- All Superinterfaces:
LocalizableObject
- All Known Implementing Classes:
ApplicationException,DuplicateObjectException,ObjectMismatchException,ObjectNotFoundException,ReadOnlyException,RuntimeIoException
Interface for an object that can be
translated to a given Locale. It is
the API to abstract from NlsMessage provided by mmm-nls. To minimize dependencies you can mock it
with ofStatic(String) wrapping a regular String. For real native language support (NLS) add
mmm-nls as dependency and require module io.github.mmm.nls.-
Method Summary
Modifier and TypeMethodDescriptionstatic StringcreateBundleName(Class<?> type) default ObjectgetArgument(String key) This method gets the language independent argument value for the givenkey.default Stringdefault StringgetLocalizedMessage(Locale locale) This method gets the resolved and localized message.voidgetLocalizedMessage(Locale locale, Appendable buffer) This method writes thelocalized messageto the givenAppendable.default StringATTENTION:
In most cases you wand to usegetLocalizedMessage(Locale)instead of this method.static Localizabledefault LocalizableThis method is the equivalent toObject.toString()with native language support.
-
Method Details
-
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
This method tries to get thelocalized messageasStringusing thedefault locale. ATTENTION:
If possible try to avoid using this method and usegetLocalizedMessage(Locale)instead (e.g. using springLocaleContextHolderto get the users locale).- Returns:
- the localized message.
-
getLocalizedMessage
This method gets the resolved and localized message.- Parameters:
locale- is the locale to translate to.- Returns:
- the localized message.
-
getLocalizedMessage
- Parameters:
locale- theLocaleto translate to.buffer- theAppendablewhere towritethe message to.- See Also:
-
toLocalizable
Description copied from interface:LocalizableObjectThis method is the equivalent toObject.toString()with native language support.- Specified by:
toLocalizablein interfaceLocalizableObject- Returns:
- an
Localizablerepresenting this object.
-
getArgument
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
nullif NOT defined.
-
ofStatic
- Parameters:
message- themessage.- Returns:
- a dummy implementation of
Localizablefor the givenmessagethat does not support localization and simply ignores any givenLocale.
-
createBundleName
- Parameters:
type- theClassreflecting the context of the localization (e.g.EnumorNlsMessage).- Returns:
- the derived
bundle namefor the givenClass.
-