getString method

IntlString? getString({
  1. Locale? locale,
})

Given a locale, return the corresponding IntlString if it exists.

If not, it will return the first IntlString that matches the locale's language (but not region).

As a final try, it will return the IntlString that matches the fallbackLocale.

If no match can be found, a Failure Result will be returned.

If locale is not set or is null, the defaultLocale will be used

Implementation

IntlString? getString({Locale? locale}) {
  locale ??= defaultLocale;

  var v = _strings[locale];

  if (v != null) {
    return v;
  }

  Locale ll = Locale.parse(Intl.shortLocale(locale.toLanguageTag()));

  v = _strings[ll];

  if (v != null) {
    return v;
  }

  v = _strings[fallbackLocale];
  if (v != null) {
    return v;
  }

  return null;
}