loadFile method

Future<void> loadFile(
  1. String path, {
  2. String? locale,
})

Load locale from a specific file. The file must be a valid YAML or JSON file. The name of the file will be used as the locale name if locale is null. For example, if the file is named en.yaml, the locale name will be en. If a locale with the same name already exists, it will be overwritten. The method will be skipped if the application is running in a web environment.

Throws a StateError if the file is not a valid YAML or JSON file.

Implementation

Future<void> loadFile(String path, {String? locale}) async {
  final content = await getFileContent(path);
  if (content == null) {
    throw StateError('File $path does not exist.');
  }
  final name = path.split('/').last.split('.').first;
  loadYaml(name, content);
}