read static method

Future<TranslationExport> read(
  1. String directory
)

Reads the keys.json in directory.

Throws FormatException when the directory holds no export, or holds one this version cannot read. Both name what was found and what was expected, since the reader is usually looking at build output from elsewhere.

Implementation

static Future<TranslationExport> read(String directory) async {
  var file = File(
    '$directory${Platform.pathSeparator}$translationExportFile',
  );
  if (!file.existsSync()) {
    throw FormatException(
      'No $translationExportFile in "$directory". '
      'Run the translations export first.',
    );
  }
  return fromJson(switch (jsonDecode(await file.readAsString())) {
    Map json => json.cast<String, Object?>(),
    var other => throw FormatException(
      '${file.path} is ${other.runtimeType}, not an object.',
    ),
  }, directory: directory);
}