parseMessage method

MessageWithMetadata parseMessage(
  1. Map<String, dynamic> arb,
  2. String messageKey,
  3. String debugString
)

Implementation

MessageWithMetadata parseMessage(
  Map<String, dynamic> arb,
  String messageKey,
  String debugString,
) {
  final messageContent = arb[messageKey] as String;
  final message = MessageParser.parse(
    debugString,
    messageContent,
    messageKey,
    addId: addName,
  );
  final messageMetadata = arb['@$messageKey'];
  if (messageMetadata != null) {
    final metadata = messageMetadata as Map<String, dynamic>;
    final placeholdersMap = metadata['placeholders'] as Map<String, dynamic>?;
    final placeholders = placeholdersMap ?? <String, dynamic>{};
    final placeholdersWithMetadata = parsePlaceholderMetadata(placeholders);

    message.placeholders = message.placeholders
        .map((placeholder) => placeholdersWithMetadata.firstWhere(
              (p) => p.name == placeholder.name,
              orElse: () => placeholder,
            ))
        .toList();
  }
  return message;
}