Interface Localizable

All Superinterfaces:
LocalizableObject
All Known Implementing Classes:
ApplicationException, DuplicateObjectException, ObjectMismatchException, ObjectNotFoundException, ReadOnlyException, RuntimeIoException

public interface Localizable extends LocalizableObject
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 Details

    • getMessage

      default String getMessage()
      ATTENTION:
      In most cases you wand to use getLocalizedMessage(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

      default String getLocalizedMessage()
      This method tries to get the localized message as String using the default locale. ATTENTION:
      If possible try to avoid using this method and use getLocalizedMessage(Locale) instead (e.g. using spring LocaleContextHolder 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)
      This method writes the localized message to the given Appendable.
      Parameters:
      locale - the Locale to translate to.
      buffer - the Appendable where to write the message to.
      See Also:
    • toLocalizable

      default Localizable toLocalizable()
      Description copied from interface: LocalizableObject
      This method is the equivalent to Object.toString() with native language support.
      Specified by:
      toLocalizable in interface LocalizableObject
      Returns:
      an Localizable representing this object.
    • getArgument

      default Object getArgument(String key)
      This method gets the language independent argument value for the given key.
      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 - the message.
      Returns:
      a dummy implementation of Localizable for the given message that does not support localization and simply ignores any given Locale.
    • createBundleName

      static String createBundleName(Class<?> type)
      Parameters:
      type - the Class reflecting the context of the localization (e.g. Enum or NlsMessage).
      Returns:
      the derived bundle name for the given Class.