load method
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 {
ByteData? data;
// Only try the regional `<lang>_<country>.po` asset when a country code
// is actually present, otherwise the path becomes `<lang>_null.po`.
final countryCode = locale.countryCode;
if (countryCode != null && countryCode.isNotEmpty) {
data = await _tryLoad(
'assets/i18n/${locale.languageCode}_$countryCode.po',
);
}
data ??= await _tryLoad('assets/i18n/${locale.languageCode}.po');
data ??= await _tryLoad('assets/i18n/$defaultLanguage.po');
// If no PO file was found, use default strings.
if (data == null) {
return GettextLocalizations.fromPO(
'msgid ""\nmsgstr ""\n"Language: $defaultLanguage\\n"\n',
onWarning: onWarning,
);
}
return GettextLocalizations.fromBytes(
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes),
onWarning: onWarning,
);
}