loadMessages method

Future<void> loadMessages(
  1. Locale locale,
  2. AssetPathResource resource,
  3. MessageSourceLoader loader
)

Load messages for a specific locale from a resource.

This method uses the provided loader to parse the resource and stores the resulting messages for the given locale. Multiple calls for the same locale will merge the messages.

Parameters:

  • locale: The locale to load messages for
  • resource: The resource containing the messages
  • loader: The loader to use for parsing the resource

Example:

await messageSource.loadMessages(
  Locale('es', 'MX'),
  AssetPathResource('messages_es_MX.properties'),
  PropertiesMessageLoader(),
);

Implementation

Future<void> loadMessages(Locale locale, AssetPathResource resource, MessageSourceLoader loader) async {
  try {
    final messages = await loader.load(resource);

    // Initialize locale map if not exists
    _messages[locale] ??= <String, String>{};

    // Merge messages (later loaded messages override earlier ones)
    _messages[locale]?.addAll(messages);

  } catch (e) {
    throw MessageSourceException(
      'Failed to load messages for locale ${locale.getLanguageTag()}',
      code: locale.getLanguageTag(),
      locale: locale,
      resource: resource.getResourcePath(),
    );
  }
}