parseResources function

Resources parseResources(
  1. Config arguments
)

Implementation

Resources parseResources(Config arguments) {
  final pubspecFile = File(arguments.pubspecFilename).absolute;
  if (!pubspecFile.existsSync()) {
    exit(1);
  }

  final yaml = loadYaml(pubspecFile.readAsStringSync()) as YamlMap;

  final primaryLocales = parseStrings(arguments.intlFilename);
  final featureLocales =
      parseFeatureStrings(arguments.intlFilename, arguments.i18nFeatures);

  if (primaryLocales != null && featureLocales != null) {
    // Make sure feature-only locales are added to the primary locale list.
    final featureOnlyLocales = <Locale>[];
    for (final feature in featureLocales) {
      for (final locale in feature.locales.locales) {
        if (!primaryLocales.locales.any((e) => e.locale == locale.locale)) {
          featureOnlyLocales.add(locale.locale);
        }
      }
    }

    if (featureOnlyLocales.isNotEmpty) {
      primaryLocales.locales
          .addAll(featureOnlyLocales.map((e) => I18nLocale(e, [])));
    }
  }

  return Resources(
    fonts: parseFonts(yaml),
    assets: parseAssets(yaml, arguments.ignoreAssets, arguments.assetClasses),
    i18n: primaryLocales,
    i18nFeatures: featureLocales,
  );
}