BloomCatalog.fromJson constructor

BloomCatalog.fromJson(
  1. String locale,
  2. Map<String, dynamic> json
)

Creates a BloomCatalog from a dynamic map, converting values to strings.

Useful when parsing translation bundles loaded from JSON assets or network endpoints.

final rawJson = {'home.title': 'Dashboard', 'home.unread': '{count, plural, =0 {None} other {# unread}}'};
final catalog = BloomCatalog.fromJson('en-US', rawJson);

Implementation

factory BloomCatalog.fromJson(String locale, Map<String, dynamic> json) {
  final messages = <String, String>{};
  json.forEach((key, value) {
    if (value != null) {
      messages[key] = value.toString();
    }
  });
  return BloomCatalog(locale, messages);
}