getFallbackLocales method
Get the fallback locale chain for the given locale.
This method returns the ordered list of locales to try when resolving messages, implementing the fallback strategy.
Example for Locale('fr', 'CA', 'Quebec'):
- fr-CA-Quebec
- fr-CA
- fr
- Default locale (if different)
Implementation
List<Locale> getFallbackLocales(Locale locale) {
// If locale is the default, return only that
if (locale.matches(_defaultLocale)) {
return [locale];
}
final fallbacks = <Locale>[locale];
// Add variant fallback
if (locale.hasVariant()) {
fallbacks.add(Locale(locale.getLanguage(), locale.getCountry()));
}
// Add country fallback
if (locale.hasCountry()) {
fallbacks.add(Locale(locale.getLanguage()));
}
// Add default locale fallback
if (!locale.matches(_defaultLocale)) {
fallbacks.add(_defaultLocale);
}
return fallbacks;
}