load method

  1. @override
Future<LocaleNames> load(
  1. Locale locale
)
override

Start loading the resources for locale. The returned future completes when the resources have finished loading.

It's assumed that this method will return an object that contains a collection of related string resources (typically defined with one method per resource). The object will be retrieved with Localizations.of.

Implementation

@override
Future<LocaleNames> load(Locale locale) async {
  final String canonicalLocale = Intl.canonicalizedLocale(locale.toString());

  String localeToLoad;
  try {
    localeToLoad =
        Intl.verifiedLocale(canonicalLocale, (l) => locales.contains(l)) ??
            fallbackLocale;
  } catch (_) {
    print(
        "Locale $locale is not an available locale. Falling back to '$fallbackLocale'. "
        "Specify a different fallback locale with [LocaleNamesLocalizationsDelegate.fallbackLocale].");
    localeToLoad = fallbackLocale;
  }

  final data = Map<String, String>.from(
      await _loadJSON('data/$localeToLoad.json') as Map<dynamic, dynamic>);
  return LocaleNames(localeToLoad, data);
}