deleteLocaleFile method

Future<void> deleteLocaleFile(
  1. String locale
)

Deletes a locale file permanently.

Implementation

Future<void> deleteLocaleFile(String locale) async {
  final normalizedLocale = locale.trim().replaceAll('-', '_');
  if (!_isLocaleCode(normalizedLocale)) {
    throw ArgumentError('Invalid locale code: "$locale"');
  }

  String filePath;
  switch (config.format) {
    case CatalogFileFormat.json:
      filePath = PathUtils.join(_langDirectoryPath, '$normalizedLocale.json');
      break;
    case CatalogFileFormat.yaml:
      filePath = PathUtils.join(_langDirectoryPath, '$normalizedLocale.yaml');
      break;
    case CatalogFileFormat.csv:
      filePath = PathUtils.join(_langDirectoryPath, '$normalizedLocale.csv');
      break;
    case CatalogFileFormat.arb:
      filePath = PathUtils.join(_langDirectoryPath, '${config.arbFilePrefix}_$normalizedLocale.arb');
      break;
  }

  final file = File(filePath);
  if (!file.existsSync()) {
    throw CatalogRepositoryException('Locale file for "$normalizedLocale" does not exist.');
  }

  await file.delete();
}