ConfigurableMessageSource class
Main implementation of MessageSource that supports loading messages from multiple resources and formats.
This class allows you to configure message sources by loading different message files for different locales using pluggable loaders for various formats (JSON, YAML, Properties).
Example usage:
final messageSource = ConfigurableMessageSource(
defaultLocale: Locale('en', 'US')
);
// Load English messages from JSON
await messageSource.loadMessages(
Locale('en'),
AssetPathResource('messages_en.json'),
loader: JsonMessageLoader(),
);
// Load French messages from YAML
await messageSource.loadMessages(
Locale('fr'),
AssetPathResource('messages_fr.yaml'),
loader: YamlMessageLoader(),
);
// Use the messages
print(messageSource.getMessage('greeting', locale: Locale('fr')));
- Inheritance
-
- Object
- AbstractMessageSource
- ConfigurableMessageSource
Constructors
- ConfigurableMessageSource({Locale? defaultLocale})
- Main implementation of MessageSource that supports loading messages from multiple resources and formats.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addMessage(
Locale locale, String code, String message) → void - Add a single message for a specific locale.
-
addMessages(
Locale locale, Map< String, String> messages) → void - Add multiple messages for a specific locale.
-
clear(
) → void - Clear all loaded messages.
-
formatMessage(
String template, List< Object> args) → String -
Format message by substituting placeholders with arguments.
inherited
-
getDefaultLocale(
) → Locale -
Get the default locale
inherited
-
getFallbackLocales(
Locale locale) → List< Locale> -
Get the fallback locale chain for the given locale.
inherited
-
getLoadedLocales(
) → Set< Locale> - Get all locales that have messages loaded.
-
getMessage(
String code, {List< Object> ? args, Locale? locale, String? defaultMessage}) → String -
Retrieve a message for the given code.
inherited
-
getMessageCount(
Locale locale) → int - Get the number of messages loaded for a specific locale.
-
hasMessages(
Locale locale) → bool - Check if messages are loaded for a specific locale.
-
loadMessages(
Locale locale, AssetPathResource resource, MessageSourceLoader loader) → Future< void> - Load messages for a specific locale from a resource.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
removeMessages(
Locale locale) → void - Remove all messages for a specific locale.
-
resolveMessage(
String code, Locale locale) → String? -
Resolve a message for the given code and locale.
override
-
toString(
) → String -
Get a string representation of the message source.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited