DelegatingMessageSource class

A message source with no messages of its own: it asks its parent, or fails when there is none.

The context registers one as messageSource when the application declares no such bean, so that a child context uses its parent's messages and a context without messages still answers (with a default message or a NoSuchMessageException). Applications do not create it.

final source = DelegatingMessageSource(parentContext);
source.getMessage('app.title'); // resolved by the parent

Spring (Java):

var source = new DelegatingMessageSource();
source.setParentMessageSource(parentContext);
Inheritance

Constructors

DelegatingMessageSource([MessageSource? parent])
Creates a source that forwards every lookup to parent, if any.

Properties

alwaysUseMessageFormat ↔ bool
Whether messages without arguments are formatted too, so that their quotes follow MessageFormat rules ('' becomes '); false by default, which returns them as written. When it is true, an invalid pattern throws a FormatException instead of being returned as is.
getter/setter pairinherited
commonMessages ↔ Map<String, String>?
Messages that are the same in every language, by code; tried after all locales and before the parent.
getter/setter pairinherited
defaultLocale ↔ String
The locale tried after the requested one (Spring's default locale), for example the language most texts are written in; empty means none (see fallbackLocale).
getter/setter pairinherited
fallbackLocale → String
The locale tried when the requested one has no message ('' for none): defaultLocale here. ReloadableResourceBundleMessageSource uses the system locale when there is no default locale, as Spring's AbstractResourceBasedMessageSource.getDefaultLocale().
no setterinherited
hashCode → int
The hash code for this object.
no setterinherited
parentMessageSource ↔ MessageSource?
The source asked for codes this one does not have; null for none.
getter/setter pairinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
useCodeAsDefaultMessage ↔ bool
Whether an unknown code is returned as the message instead of throwing a NoSuchMessageException; false by default. Handy while translations are incomplete: the screen shows the code.
getter/setter pairinherited

Methods

formatMessage(String pattern, List<Object?> args, [String? locale]) → String
Fills args into pattern with MessageFormat; without arguments (and with alwaysUseMessageFormat off) returns pattern as it is, like Spring.
inherited
getMessage(String code, {List<Object?> args = const [], String? defaultMessage, String? locale}) → String
The text for code in locale, with args filled into its {0}, {1}, ... placeholders.
inherited
getMessageFromResolvable(MessageSourceResolvable resolvable, {String? locale}) → String
The text for the first code of resolvable found in locale, with its arguments filled in; else its default message; else a NoSuchMessageException. Use it to show validation errors and other messages described by codes.
inherited
getMessageInternal(String code, List<Object?> args, String? locale) → String?
The formatted message for code from this source, its common messages or its parent; null when none has it. Unlike getMessage, it neither throws nor uses a default message.
inherited
localeChain(String? locale) → List<String>
The locales tried for locale: its candidates, then those of fallbackLocale, ending with '' (the base).
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
renderDefaultMessage(String defaultMessage, List<Object?> args, String? locale) → String
Formats a default message with args, resolving resolvable arguments first.
inherited
resolveArguments(List<Object?> args, String? locale) → List<Object?>
Replaces each MessageSourceResolvable in args by its message in locale; other arguments stay as they are.
inherited
resolveCode(String code, String locale) → String?
The unformatted message for code in exactly locale ('' for the base), or null. This is the one method a subclass must write; the fallbacks to other locales happen around it. locale is already normalized (see Locales.normalize).
override
resolveCodeInLocales(String code, List<String> locales) → String?
The unformatted message for code in the first of locales (most specific first, ending with '') that has one, or null.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited