writeTranslations method

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

Write out the translated forms.

Implementation

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

  output.write('  static final messageText = ');
  var messages = usableTranslations
      .expand((translation) => translation.originalMessages);
  var map = <String, dynamic>{
    for (var original in messages)
      original.name: original.toJsonForLocale(locale)
  };
  var jsonEncoded = JsonEncoder().convert(map);
  output.write(_embedInLiteral(jsonEncoded));
}