writeTranslations method

void writeTranslations(
  1. Iterable<TranslatedMessage> usableTranslations,
  2. String locale
)
override

Write out the translated forms.

Implementation

void writeTranslations(
    Iterable<TranslatedMessage> usableTranslations, String locale) {
  output.write(r"""
Map<String, dynamic>? _messages;
Map<String, dynamic> get messages => _messages ??=
    const JsonDecoder().convert(messageText) as Map<String, dynamic>;
""");

  output.write("  static final messageText = ");
  var entries = usableTranslations
      .expand((translation) => translation.originalMessages);
  var map = {};
  for (var original in entries) {
    map[original.name] = original.toJsonForLocale(locale);
  }
  var jsonEncoded = new JsonEncoder().convert(map);
  output.write(_embedInLiteral(jsonEncoded));
}