load method

  1. @protected
  2. @visibleForTesting
Future<void> load(
  1. Locale locale
)

used by this class only to load the translations when locale changes

Implementation

@protected
@visibleForTesting
Future<void> load(Locale locale) async {
  /// for each loader add the values to the translation map
  final _app = <String, Object?>{};

  for (final loader in AppLang.config.loaders) {
    _app[loader.name] = await loader.load(locale);
  }

  _app.addAll(const NationsAssetsLoader().load(locale));
  final baseData = await AppLang.baseLoader.load(locale);

  final result = mergeTwoMaps(_app, baseData)?.cast<String, Object?>();

  /// * clear the old translations

  translations
    ..clear()
    ..addAll(result ?? {});

  notifyListeners();
}