load method

  1. @override
Future<GettextLocalizations> 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<GettextLocalizations> load(Locale locale) async {
  var poContent = '';
  try {
    poContent = await rootBundle.loadString('assets/i18n/${locale.languageCode}_${locale.countryCode}.po');
  } catch (e) {
    try {
      poContent = await rootBundle.loadString('assets/i18n/${locale.languageCode}.po');
    } catch (e) {
      try {
        poContent = await rootBundle.loadString('assets/i18n/$defaultLanguage.po');
      } catch (e) {
        // Ignore error, default strings will be used.
      }
    }
  }

  /// If no PO file was found, use default strings.
  if (poContent == '') {
    poContent = 'msgid ""\nmsgstr ""\n"Language: $defaultLanguage\\n"\n';
  }

  return GettextLocalizations.fromPO(poContent);
}