generateLocalesImportFile method

String generateLocalesImportFile()

This section generates the messages_all_locales.dart file based on the list of allLocales.

Implementation

String generateLocalesImportFile() {
  clearOutput();
  output.write(localesPrologue);
  for (var locale in allLocales) {
    var baseFile = '${generatedFilePrefix}messages_$locale.dart';
    var file = importForGeneratedFile(baseFile);
    output.write("import '$file' ");
    if (useDeferredLoading) output.write('deferred ');
    output.write('as ${libraryName(locale)};\n');
  }
  output.write('\n');
  output.write('typedef Future<dynamic> LibraryLoader();\n');
  output.write('Map<String, LibraryLoader> _deferredLibraries = {\n');
  for (var rawLocale in allLocales) {
    var locale = Intl.canonicalizedLocale(rawLocale);
    var loadOperation = (useDeferredLoading)
        ? "  '$locale': ${libraryName(locale)}.loadLibrary,\n"
        : "  '$locale': () => Future.value(null),\n";
    output.write(loadOperation);
  }
  output.write('};\n');
  output.write('\nMessageLookupByLibrary? _findExact(String localeName) {\n'
      '  switch (localeName) {\n');
  for (var rawLocale in allLocales) {
    var locale = Intl.canonicalizedLocale(rawLocale);
    output.write(
        "    case '$locale':\n      return ${libraryName(locale)}.messages;\n");
  }
  output.write(localesClosing);
  return output.toString();
}