load static method

Future<Config> load(
  1. String projectDir
)

Implementation

static Future<Config> load(String projectDir) async {
  final configFile = File(path.join(projectDir, 'l10n', 'config.json'));
  if (await configFile.exists()) {
    final jsonContent = await configFile.readAsString();
    final Map<String, dynamic> config = json.decode(jsonContent);
    final List<dynamic> locales = config['supported_locales'];

    if (locales.isEmpty) {
      throw Exception('No supported locales specified in config file');
    }

    if (config['to'] == null) {
      throw Exception('Output directory not specified in config file');
    }

    if (config['main_locale'] == null) {
      throw Exception('Main locale not specified in config file');
    }

    if (config['main_locale'] != null &&
        !locales.contains(config['main_locale'])) {
      throw Exception('Main locale not found in supported locales');
    }

    return Config(
      from: path.join(projectDir, 'l10n'),
      to: config['to'],
      mainLocale: config['main_locale'],
      supportedLocales: locales.map((e) => e.toString()).toSet(),
    );
  }

  throw Exception('Config file not found in $projectDir');
}