Class TranslationMessageSource
- All Implemented Interfaces:
org.springframework.context.MessageSource
MessageSource backed by the translation store.
There are no messages_*.properties in this application. Registered as the primary
MessageSource, this means anything reaching for one — a Spring internal, a
library — gets the same text an administrator edits, rather than a second source of
truth nobody remembers exists.
Implements the interface rather than extending AbstractMessageSource, whose
resolveCode hook is typed to return a java.text.MessageFormat. Patterns
here are ICU, which is a different class and not a subtype, so the base class has nowhere
to put one. What it offered — a format cache and a code-fallback loop — is a few lines
below, and the store is already cached in front of this.
Application code should still use MessageResolver: it is one dependency instead
of a locale plus a key plus a fallback decision at each call site, and it takes named
arguments, which is what the translations are written against.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@Nullable StringgetMessage(String code, @Nullable Object @Nullable [] args, @Nullable String defaultMessage, @Nullable Locale locale) getMessage(String code, @Nullable Object @Nullable [] args, @Nullable Locale locale) getMessage(org.springframework.context.MessageSourceResolvable resolvable, @Nullable Locale locale) Tries each code in turn, which is how Spring's own validation messages degrade.
-
Constructor Details
-
TranslationMessageSource
public TranslationMessageSource()
-
-
Method Details
-
getMessage
-
getMessage
-
getMessage
public String getMessage(org.springframework.context.MessageSourceResolvable resolvable, @Nullable Locale locale) Tries each code in turn, which is how Spring's own validation messages degrade.A resolvable carries codes from most to least specific, and the contract is that the first one with text wins.
- Specified by:
getMessagein interfaceorg.springframework.context.MessageSource
-