contentForLocale method

String contentForLocale(
  1. String basicLocale,
  2. Iterable<TranslatedMessage> translations
)

Generate a string that containts the dart code with the translations in locale.

Implementation

String contentForLocale(
    String basicLocale, Iterable<TranslatedMessage> translations) {
  clearOutput();
  var locale = new MainMessage()
      .escapeAndValidateString(Intl.canonicalizedLocale(basicLocale));
  output.write(prologue(locale));
  // Exclude messages with no translation and translations with no matching
  // original message (e.g. if we're using some messages from a larger
  // catalog)
  var usableTranslations = translations
      .where(
          (each) => each.originalMessages.isNotEmpty && each.message != null)
      .toList();
  for (var each in usableTranslations) {
    for (var original in each.originalMessages) {
      original.addTranslation(locale, each.message!);
    }
  }
  usableTranslations.sort((a, b) =>
      a.originalMessages.first.name.compareTo(b.originalMessages.first.name));

  writeTranslations(usableTranslations, locale);

  return '$output';
}