writeTranslations method

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

Write out the translated forms.

Implementation

void writeTranslations(
    Iterable<TranslatedMessage> usableTranslations, String locale) {
  for (var translation in usableTranslations) {
    // Some messages we generate as methods in this class. Simpler ones
    // we inline in the map from names to messages.
    var messagesThatNeedMethods =
        translation.originalMessages.where(_hasArguments).toSet().toList();
    for (var original in messagesThatNeedMethods) {
      output
        ..write("  ")
        ..write(
            original.toCodeForLocale(locale, _methodNameFor(original.name)))
        ..write("\n\n");
    }
  }
  output.write(messagesDeclaration);

  // Now write the map of names to either the direct translation or to a
  // method.
  var entries = (usableTranslations
          .expand((translation) => translation.originalMessages)
          .toSet()
          .toList()
        ..sort((a, b) => a.name.compareTo(b.name)))
      .map((original) =>
          '    "${original.escapeAndValidateString(original.name)}" '
          ': ${_mapReference(original, locale)}');
  output
    ..write(entries.join(",\n"))
    ..write("\n  };\n}\n");
}