Class TranslationMessageSource

java.lang.Object
com.vertyll.freshly.web.i18n.TranslationMessageSource
All Implemented Interfaces:
org.springframework.context.MessageSource

@Component("messageSource") public class TranslationMessageSource extends Object implements org.springframework.context.MessageSource
A 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 Details

    • TranslationMessageSource

      public TranslationMessageSource()
  • Method Details

    • getMessage

      public @Nullable String getMessage(String code, @Nullable Object @Nullable [] args, @Nullable String defaultMessage, @Nullable Locale locale)
      Specified by:
      getMessage in interface org.springframework.context.MessageSource
    • getMessage

      public String getMessage(String code, @Nullable Object @Nullable [] args, @Nullable Locale locale)
      Specified by:
      getMessage in interface org.springframework.context.MessageSource
    • 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:
      getMessage in interface org.springframework.context.MessageSource