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
-
- Object
- AbstractMessageSource
- DelegatingMessageSource
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');falseby default, which returns them as written. When it istrue, an invalid pattern throws aFormatExceptioninstead 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.ReloadableResourceBundleMessageSourceuses the system locale when there is no default locale, as Spring'sAbstractResourceBasedMessageSource.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;
nullfor 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;
falseby 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
argsintopatternwith MessageFormat; without arguments (and with alwaysUseMessageFormat off) returnspatternas it is, like Spring.inherited -
getMessage(
String code, {List< Object?> args = const [], String? defaultMessage, String? locale}) → String -
The text for
codeinlocale, withargsfilled into its{0},{1}, ... placeholders.inherited -
getMessageFromResolvable(
MessageSourceResolvable resolvable, {String? locale}) → String -
The text for the first code of
resolvablefound inlocale, 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
codefrom this source, its common messages or its parent;nullwhen 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
argsby its message inlocale; other arguments stay as they are.inherited -
resolveCode(
String code, String locale) → String? -
The unformatted message for
codein exactlylocale(''for the base), ornull. This is the one method a subclass must write; the fallbacks to other locales happen around it.localeis already normalized (seeLocales.normalize).override -
resolveCodeInLocales(
String code, List< String> locales) → String? -
The unformatted message for
codein the first oflocales(most specific first, ending with'') that has one, ornull.inherited -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited