Class LocalizationMessageSource

  • All Implemented Interfaces:
    org.springframework.context.HierarchicalMessageSource, org.springframework.context.MessageSource

    public class LocalizationMessageSource
    extends org.springframework.context.support.AbstractMessageSource
    The standard Molgenis MessageSource which looks up messages in the MessageResolution and delegates MessageFormat creation to a MessageFormatFactory.

    Marks missing values with # characters.

    Caching should be done by the MessageResolution.

    • Field Summary

      • Fields inherited from class org.springframework.context.support.MessageSourceSupport

        logger
    • Constructor Summary

      Constructors 
      Constructor Description
      LocalizationMessageSource​(org.molgenis.util.i18n.format.MessageFormatFactory messageFormatFactory, MessageResolution messageRepository, java.util.function.Supplier<java.util.Locale> fallbackLocaleSupplier)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.text.MessageFormat createMessageFormat​(java.lang.String msg, java.util.Locale locale)  
      java.lang.String getDefaultMessage​(java.lang.String code)
      The default message adds # marks around the code so that they stand out as not yet translated.
      java.text.MessageFormat resolveCode​(java.lang.String code, java.util.Locale locale)
      Looks up the MessageFormat for a code.
      protected java.lang.String resolveCodeWithoutArguments​(java.lang.String code, java.util.Locale locale)
      Looks up a code in the MessageResolution.
      • Methods inherited from class org.springframework.context.support.AbstractMessageSource

        getCommonMessages, getDefaultMessage, getMessage, getMessage, getMessage, getMessageFromParent, getMessageInternal, getParentMessageSource, isUseCodeAsDefaultMessage, resolveArguments, setCommonMessages, setParentMessageSource, setUseCodeAsDefaultMessage
      • Methods inherited from class org.springframework.context.support.MessageSourceSupport

        formatMessage, isAlwaysUseMessageFormat, renderDefaultMessage, setAlwaysUseMessageFormat
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LocalizationMessageSource

        public LocalizationMessageSource​(org.molgenis.util.i18n.format.MessageFormatFactory messageFormatFactory,
                                         MessageResolution messageRepository,
                                         java.util.function.Supplier<java.util.Locale> fallbackLocaleSupplier)
    • Method Detail

      • getDefaultMessage

        public java.lang.String getDefaultMessage​(java.lang.String code)
        The default message adds # marks around the code so that they stand out as not yet translated.
        Overrides:
        getDefaultMessage in class org.springframework.context.support.AbstractMessageSource
        Parameters:
        code - the untranslated code
        Returns:
        the code surrounded by `#` characters.
      • resolveCode

        public java.text.MessageFormat resolveCode​(java.lang.String code,
                                                   java.util.Locale locale)
        Looks up the MessageFormat for a code.
        Specified by:
        resolveCode in class org.springframework.context.support.AbstractMessageSource
        Parameters:
        code - the code to look up
        locale - the Locale for which the code should be looked up
        Returns:
        newly created MessageFormat
      • createMessageFormat

        protected java.text.MessageFormat createMessageFormat​(java.lang.String msg,
                                                              java.util.Locale locale)
        Overrides:
        createMessageFormat in class org.springframework.context.support.MessageSourceSupport
      • resolveCodeWithoutArguments

        protected java.lang.String resolveCodeWithoutArguments​(java.lang.String code,
                                                               @Nullable @CheckForNull
                                                               java.util.Locale locale)
        Looks up a code in the MessageResolution.

        First tries the given locale if it is nonnull, then the fallbackLocale and finally the default locale.

        Overrides:
        resolveCodeWithoutArguments in class org.springframework.context.support.AbstractMessageSource
        Parameters:
        code - the messageID to look up.
        locale - the Locale whose language code should be tried first, may be null
        Returns:
        The message, or null if none found.