Package org.molgenis.i18n
Class LocalizationMessageSource
- java.lang.Object
-
- org.springframework.context.support.MessageSourceSupport
-
- org.springframework.context.support.AbstractMessageSource
-
- org.molgenis.i18n.LocalizationMessageSource
-
- All Implemented Interfaces:
org.springframework.context.HierarchicalMessageSource,org.springframework.context.MessageSource
public class LocalizationMessageSource extends org.springframework.context.support.AbstractMessageSourceThe standard MolgenisMessageSourcewhich looks up messages in theMessageResolutionand delegatesMessageFormatcreation to aMessageFormatFactory.Marks missing values with # characters.
Caching should be done by the
MessageResolution.
-
-
Constructor Summary
Constructors Constructor Description LocalizationMessageSource(MessageFormatFactory messageFormatFactory, MessageResolution messageRepository, Supplier<Locale> fallbackLocaleSupplier)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected MessageFormatcreateMessageFormat(String msg, Locale locale)StringgetDefaultMessage(String code)The default message adds # marks around the code so that they stand out as not yet translated.MessageFormatresolveCode(String code, Locale locale)Looks up theMessageFormatfor a code.protected StringresolveCodeWithoutArguments(String code, Locale locale)Looks up a code in theMessageResolution.-
Methods inherited from class org.springframework.context.support.AbstractMessageSource
getCommonMessages, getDefaultMessage, getMessage, getMessage, getMessage, getMessageFromParent, getMessageInternal, getParentMessageSource, isUseCodeAsDefaultMessage, resolveArguments, setCommonMessages, setParentMessageSource, setUseCodeAsDefaultMessage
-
-
-
-
Constructor Detail
-
LocalizationMessageSource
public LocalizationMessageSource(MessageFormatFactory messageFormatFactory, MessageResolution messageRepository, Supplier<Locale> fallbackLocaleSupplier)
-
-
Method Detail
-
getDefaultMessage
public String getDefaultMessage(String code)
The default message adds # marks around the code so that they stand out as not yet translated.- Overrides:
getDefaultMessagein classorg.springframework.context.support.AbstractMessageSource- Parameters:
code- the untranslated code- Returns:
- the code surrounded by `#` characters.
-
resolveCode
public MessageFormat resolveCode(String code, Locale locale)
Looks up theMessageFormatfor a code.- Specified by:
resolveCodein classorg.springframework.context.support.AbstractMessageSource- Parameters:
code- the code to look uplocale- theLocalefor which the code should be looked up- Returns:
- newly created
MessageFormat
-
createMessageFormat
protected MessageFormat createMessageFormat(String msg, Locale locale)
- Overrides:
createMessageFormatin classorg.springframework.context.support.MessageSourceSupport
-
resolveCodeWithoutArguments
protected String resolveCodeWithoutArguments(String code, @Nullable @CheckForNull Locale locale)
Looks up a code in theMessageResolution.First tries the given locale if it is nonnull, then the fallbackLocale and finally the default locale.
- Overrides:
resolveCodeWithoutArgumentsin classorg.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.
-
-